wonderbox 0.4.0

A minimalistic IoC library.
Documentation

A minimalistic IoC library.

Examples

use wonderbox::{autoresolvable, register_autoresolvable, Container};

trait Foo {}

#[derive(Debug, Default)]
struct FooImpl {
stored_string: String,
}

#[autoresolvable]
impl FooImpl {
fn new(stored_string: String) -> Self {
Self { stored_string }
}
}

impl Foo for FooImpl {}

let mut container = Container::new();
container.register(|_| "foo".to_string());
register_autoresolvable!(container, FooImpl as Box<dyn Foo>);

let foo = container.try_resolve::<Box<dyn Foo>>();
assert!(foo.is_some())