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();
builder
.register::<FooImpl>()
.as_type::<Foo>();
let mut container = builder.build().unwrap();
let foo = container
.with_named_parameter::<Foo, String>("name", "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();
builder
.register::<FooImpl>()
.as_type::<Foo>()
.with_named_parameter("name", "fooooo".to_string());
}