runtime_injector

Crates.ioruntime_injector
lib.rsruntime_injector
version0.4.0
sourcesrc
created_at2021-03-28 20:53:27.001013
updated_at2021-05-14 06:48:02.151505
descriptionRuntime dependency injection container
homepage
repositoryhttps://github.com/TehPers/runtime_injector
max_upload_size
id374823
size144,829
TehPers (TehPers)

documentation

https://docs.rs/runtime_injector

README

runtime_injector

Current version Current documentation

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.

Commit count: 159

cargo fmt