Crates.io | rustyinject |
lib.rs | rustyinject |
version | 0.1.1 |
source | src |
created_at | 2024-06-13 05:47:36.19594 |
updated_at | 2024-06-13 07:12:09.694268 |
description | Zero-cost, compile-time DI framework for Rust |
homepage | |
repository | https://github.com/AlexSherbinin/rustyinject |
max_upload_size | |
id | 1270242 |
size | 29,837 |
Rustyinject is a compile-time DI library for Rust.
Dependency Injection is a design pattern used to implement IoC (Inversion of Control), allowing the creation, storage, and retrieval of dependencies in a flexible and decoupled manner. This provides a container for DI that can:
Here is an example of how to use the DI container:
use rustyinject::{DependencyContainer, injector::{factories::ConstructorFactory, Injector}};
struct MyService {
// Some fields
}
impl ConstructorFactory for MyService {
type Dependencies<'a> = (); // Specify your dependencies here.
fn build(dependencies: Self::Dependencies<'_>) -> Self {
Self {
// Some fields
}
}
}
let container = DependencyContainer::default()
.with_constructor_factory::<MyService>();
let my_service: MyService = (&container).inject();
Contributions are welcome! Feel free to open issues or submit pull requests.
This project is licensed under the MIT License. See the LICENSE file for details.