See examples/get_started.rs for list of available injection options
Annotate structure with #[component]
```rust
struct Comp {} ```
Annotate impl blocks with #[provides]
```rust
impl Interface for Comp {} ```
Create container:
rust
fn main() {
let mut container = Container::<profiles::Default>::new();
}
Get dependency ref:
rust
fn main() {
let comp = Provider::<dyn Interface>::get(&mut container);
}
For Rc:
```rust
struct Dependency;
struct Comp {
dependency_rc: Rc
fn main() {
let mut container = Container::
For &ref
```rust
struct Comp<'a> { dependency_ref: &'a Dependency }
fn main() {
let mut container = Container::
For create new struct instead of reference:
```rust
struct Comp {
dependency_box: Box
fn main() {
let mut container = Container::
It uses config
crate under the hood, for example it tries to find float_prop
in environment, after that tries config/default.toml
, after that config/{profile}.toml
```rust
struct Comp { config: Config, #[prop("int")] intprop: usize, floatprop: f32 } ```
Use Deferred type:
```rust
struct Comp<'a> {
dependencydefrc: Deferred
You can use predefined profiles from `waiter_di::profile" or create custom:
```rust struct CustomProfile;
impl Interface for Comp {}
fn main() {
let mut container = Container::
config/default.toml
Just define property named profile
and use inject!
macro:
let comp = inject!(Comp: profiles::Default, profiles::Dev);
If you can't use #[component]
annotation, use factory function instead:
```rust
fn createdependency (
) -> Dependency { Dependency } ```