Crates.io | easy-di |
lib.rs | easy-di |
version | 1.0.0-beta.3 |
source | src |
created_at | 2022-07-22 15:56:01.557439 |
updated_at | 2022-07-22 16:51:57.380922 |
description | Simple dependency injection container for Rust. |
homepage | |
repository | https://github.com/eisberg-labs/easy-di |
max_upload_size | |
id | 630875 |
size | 21,239 |
Simple dependency injection container for Rust.
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();
}
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
This project follows the Rust Code of Conduct.
Distributed under the terms of MIT license and Apache license.