Expand description
§Overview
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:
- Store singleton instances and provide them.
- Provide cloned instances of singletons.
- Create instances using factory methods.
§Usage
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();
Modules§
- indecies
- Indecies for indexing
DepsList
andDependencyContainer
- injector
- Injector trait, containers and strategies needed for dependency injection.
Structs§
- Dependency
Container - An Inversion of Control (IoC) container used for declaring and managing dependencies in a Rust application. It facilitates the creation, storage, and retrieval of dependencies, supporting both singleton and factory-based dependency injection.
Traits§
- Deps
List - Heterogeneously-typed list for storing dependencies.
- Deps
List GetMut - Trait for getting mutable references to the dependencies in the heterogeneously-typed list.
- Deps
List GetRef - Trait for getting immutable references to the dependencies in the heterogeneously-typed list.
- Deps
List Remove - Trait for removing dependencies from the heterogeneously-typed list.