Crates.io | runtime_injector |
lib.rs | runtime_injector |
version | 0.4.0 |
source | src |
created_at | 2021-03-28 20:53:27.001013 |
updated_at | 2021-05-14 06:48:02.151505 |
description | Runtime dependency injection container |
homepage | |
repository | https://github.com/TehPers/runtime_injector |
max_upload_size | |
id | 374823 |
size | 144,829 |
This library provides a powerful, easy to use inversion-of-control (IoC) container with a focus on ergonomics and configurability.
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();
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.
This library is licensed under your choice of either MIT or Apache 2.0.