Expand description
All possible dependencies for injected types.
The following dependency types are available, as of right now:
Transient
: Dependencies that are created from scratch when requested.Singleton
: Dependencies that are created once for every registry.
All dependency types implement the Dep
trait, and can get access to the
inner type via .get
.
§Examples
ⓘ
use ferrunix_core::{Registry, Singleton, Transient};
struct Template {
template: &'static str,
}
let registry = Registry::empty();
registry.transient(|| 1_u8);
registry.singleton(|| Template { template: "u8 is:" });
registry
.with_deps::<_, (Transient<u8>, Singleton<Template>)>()
.transient(|(num, template)| {
let num = num.get(); // grab the inner `u8`.
format!("{} {num}", template.template) // you can also use the `Deref` impl.
});
let s = registry.transient::<String>().unwrap();
assert_eq!(s, "u8 is: 1".to_string());
Structs§
Traits§
- Dep
- Trait to specify a dependency. Every possible dependency type is implementing this trait.