#di #ioc #inversion-of-control #dependency-injection

easy-di

Simple dependency injection container for Rust

2 releases

1.0.0-beta.3 Jul 22, 2022

#17 in #inversion-of-control

37 downloads per month

MIT/Apache

9KB
140 lines

Easy DI Continuous Integration cargo-badge license-badge

Simple dependency injection container for Rust.

Example

Code:

use std::sync::Arc;
use easy_di::{Container, ServiceProvider};
pub trait Animal {
    fn make_sound(&self);
}
#[derive(Clone)]
struct Dog;
impl Animal for Dog {
    fn make_sound(&self) {
        println!("woof woof!")
    }
}

fn main() {
    let mut container = Container::new();
    let animal: Arc<dyn Animal + Sync + Send> = Arc::new(Dog);
    container.inject(animal);
    let animal2 = container.find::<Arc<dyn Animal + Sync + Send>>();
    animal2.unwrap().make_sound();
}

Contributing

This project welcomes all kinds of contributions. No contribution is too small!

If you want to contribute to this project but don't know how to begin or if you need help with something related to this project, feel free to send me an email https://www.eisberg-labs.com/ (contact form at the bottom).

Some pointers on contribution are in Contributing.md

Code of Conduct

This project follows the Rust Code of Conduct.

License

Distributed under the terms of MIT license and Apache license.

Dependencies

~0.4–1MB
~21K SLoC