7 unstable releases (3 breaking)
0.4.0 | May 14, 2021 |
---|---|
0.3.0 | May 8, 2021 |
0.2.1 | May 5, 2021 |
0.2.0 | Mar 31, 2021 |
0.1.2 | Mar 28, 2021 |
#26 in #ioc
35 downloads per month
Used in runtime_injector_actix
145KB
2K
SLoC
runtime_injector
This library provides a powerful, easy to use inversion-of-control (IoC) container with a focus on ergonomics and configurability.
Getting started
First, configure your injector:
let module = define_module! {
services = [MyService::new.transient()],
interfaces = {
dyn MyInterface = [MyInterfaceImpl::new.singleton()],
},
};
let mut builder = Injector::builder();
builder.add_module(module);
builder.provide(constant(MyConfig));
Next, create your injector and request your services from it:
let injector = builder.build();
let my_service: Svc<MyService> = injector.get().unwrap();
let my_interface_impl: Svc<dyn MyInterface> = injector.get().unwrap();
// Since `MyService` is transient, we can also request an owned instance of it
let my_service: Box<MyService> = injector.get().unwrap();
Minimum supported Rust version
As the library is still in development, the only supported Rust version is the most recent version of stable Rust. The library may work on older versions, but there is no guarantee.
License
This library is licensed under your choice of either MIT or Apache 2.0.