easy-di

Crates.ioeasy-di
lib.rseasy-di
version1.0.0-beta.3
sourcesrc
created_at2022-07-22 15:56:01.557439
updated_at2022-07-22 16:51:57.380922
descriptionSimple dependency injection container for Rust.
homepage
repositoryhttps://github.com/eisberg-labs/easy-di
max_upload_size
id630875
size21,239
Ana Bujan (amarjanica)

documentation

README

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.

Commit count: 8

cargo fmt