he_di 0.2.1

Dependency Inversion / Dependency Injection / Inversion of control container for Rust
Documentation
extern crate he_di;
#[macro_use] extern crate he_di_derive;

trait Foo {
    fn foo(&self) -> String;
}

#[derive(Component)]
#[interface(Foo)]
struct FooImpl {
    name: String,
}

impl Foo for FooImpl {
    fn foo(&self) -> String {
        self.name.clone()
    }
}

#[test]
fn container_module_doc_example_1() {
    let mut builder = he_di::ContainerBuilder::new();

    // Register `FooImpl` as a `Foo` Component
    builder
        .register::<FooImpl>()
        .as_type::<Foo>();

    let mut container = builder.build().unwrap();
    let foo = container
        .with_named_parameter::<Foo, String>("name", "fooooooo".to_string())
    //  .with_typed_parameter::<Foo, String>("fooooooo".to_string())
        .resolve::<Foo>()
        .unwrap();
    assert_eq!(foo.foo(), "fooooooo".to_string());
}

#[test]
fn container_module_doc_example_2() {
    let mut builder = he_di::ContainerBuilder::new();
    
    // Register `FooImpl` as a `Foo` Component
    builder
        .register::<FooImpl>()
        .as_type::<Foo>()
        .with_named_parameter("name", "fooooo".to_string());
    //  .with_type_parameter::<String>("fooooo".to_string()); // alternative
    // etc
}