di 0.1.2

Dependency injection container.
docs.rs failed to build di-0.1.2
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.

Dependency Injection container for Rust

Build Status

This library implements dependency injection container for Rust mimicking the way it is done in other languages and frameworks.

It differs from other popular implementations by providing a simple way to group factories together using one_of method.

Example

let mut registry = di::Registry::new();

registry
    .one_of("values", || -> i32 { 1 })
    .with_id("a")
    .insert();

registry
    .one_of("values", |a: i32| -> i32 { a + 2 })
    .with_arg("a")
    .insert();

match registry.compile() {
    Ok(container) => {
        if let Some(a) = container.get::<Vec<i32>>("values") {
            assert_eq!(vec![ 1, 1 + 2 ], a.take());
        }
    },
    Err(errors) => di::error_printer::pretty_print(&errors),
}

Of course, ungrouped dependencies are also available.

Documentation

Usage

Put this in your Cargo.toml:

[dependencies]
di = "*"

And this in your crate root:

extern crate di;

License

MIT