Crates.io | di |
lib.rs | di |
version | 0.1.2 |
source | src |
created_at | 2014-12-25 22:03:54.105064 |
updated_at | 2015-12-11 23:56:40.231265 |
description | Dependency injection container. |
homepage | |
repository | https://github.com/Nercury/di-rs |
max_upload_size | |
id | 639 |
size | 86,483 |
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.
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.
Put this in your Cargo.toml
:
[dependencies]
di = "*"
And this in your crate root:
extern crate di;
MIT