Crates.io | rscontainer |
lib.rs | rscontainer |
version | 0.1.0 |
source | src |
created_at | 2021-06-17 13:51:41.277388 |
updated_at | 2021-06-17 13:51:41.277388 |
description | Manages dependencies between objects. |
homepage | https://github.com/yvesdum/rscontainer |
repository | https://github.com/yvesdum/rscontainer |
max_upload_size | |
id | 411366 |
size | 79,063 |
rscontainer is a library for the Rust programming language to manage
dependencies between objects. The main type is the ServiceContainer
, which
serves two purposes: it acts as a registry for shared instances (singletons)
and custom constructors, and it provides a mechanism for dependency injection.
For more information see the documentation.
There are different kind of instances:
Resolving a owned instance:
use rscontainer::ServiceContainer;
let mut container = ServiceContainer::new();
let mut foo = container.resolver().owned::<SomeService>(())?;
foo.do_something();
Resolving a shared instance (singleton):
use rscontainer::{ServiceContainer, Shared};
let mut container = ServiceContainer::new();
let foo: Shared<SomeService> = container.resolver().shared()?;
foo.access_mut(|foo| {
let foo = foo.assert_healthy();
foo.do_something();
});