rscontainer 0.1.0

Manages dependencies between objects.
Documentation
  • Coverage
  • 94.74%
    36 out of 38 items documented1 out of 1 items with examples
  • Size
  • Source code size: 78.9 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 5.73 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • yvesdum/rscontainer
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • yvesdum

rscontainer

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.

Resolving instances

There are different kind of instances:

  • Owned instances: a fresh instance to be used in a owned scope. This instance will not be stored in the service container, you will get a new instance each time you resolve a owned instance.
  • Shared instances: an instance behind a smart pointer that is stored in the service container. You will get the same instance each time you resolve a shared service.
  • Some instances: an enum over owned and shared instances. Use this in a type when you want the user of your type to decide what kind of instance they want to supply.

How to use

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();
});