Rust di containers system
Library required Rust nightly
```rust
use anthill_di::{ builders::ContainerBuilder, Injector, Injection };
trait TextGetter { fn get(&self) -> String; }
struct StructWithText { text: String, }
impl Injection for StructWithText { fn buildinjection(: &mut Injector) -> Self { Self { text: "test".to_string(), } } }
impl TextGetter for StructWithText { fn get(&self) -> String { self.text.clone() } }
struct TextBox {
text_getter: Box
impl Injection for TextBox { fn buildinjection(injector: &mut Injector) -> Self { Self { textgetter: injector.getnewinstance(), } } }
fn main() {
let containers = vec![
ContainerBuilder::bindinterface::
let injector = Injector::new(containers);
let obj = injector.lock().unwrap().get_new_instance::<TextBox>();
assert_eq!(obj.text_getter.get(), "test".to_string());
}
```