5 releases (breaking)

0.5.0 Jun 7, 2019
0.4.0 May 11, 2019
0.3.0 May 8, 2019
0.2.0 May 8, 2019
0.1.0 May 6, 2019

#35 in #ioc

MIT/Apache

19KB
275 lines

Wonderbox

Build Status Latest Version Documentation

A minimalistic IoC library.

Examples

use wonderbox::Container;

trait Foo {}

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

impl FooImpl {
    fn new(stored_string: String) -> Self {
        Self { stored_string }
    }
}

impl Foo for FooImpl {}

#[test]
fn test() {
    let mut container = Container::new();
    container.register(|_| "foo".to_string());
    container.register(|container| Box::new(FooImpl::new(container.resolve())) as Box<dyn Foo>);

    let foo = container.resolve::<Box<dyn Foo>>();
}


lib.rs:

A minimalistic IoC library.

Examples

use wonderbox::Container;

trait Foo {}

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

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());
container.register(|container| Box::new(FooImpl::new(container.resolve())) as Box<dyn Foo>);

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

No runtime deps