di

Crates.iodi
lib.rsdi
version0.1.2
created_at2014-12-25 22:03:54.105064+00
updated_at2015-12-11 23:56:40.231265+00
descriptionDependency injection container.
homepage
repositoryhttps://github.com/Nercury/di-rs
max_upload_size
id639
size86,483
Nerijus Arlauskas (Nercury)

documentation

http://nercury.github.io/di-rs/di/index.html

README

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

Commit count: 0

cargo fmt