Skip to main content

hosting_di/
lib.rs

1//! Dependency injection container: register services in a
2//! [`ServiceCollection`], build it into a [`ServiceProvider`], then resolve.
3
4#![warn(missing_docs, missing_debug_implementations)]
5
6mod abstraction;
7mod collection;
8mod container;
9mod error;
10mod graph;
11mod key;
12mod resolver;
13mod scope;
14mod service;
15mod sync;
16
17pub use abstraction::CastFrom;
18pub use collection::ServiceCollection;
19pub use container::ServiceProvider;
20pub use error::{BoxError, BuildError, BuildIssue, ResolveError};
21pub use key::Dependency;
22pub use resolver::Resolver;
23pub use scope::Scope;
24pub use service::Service;
25
26#[doc(hidden)]
27pub mod __private {
28    pub use crate::service::{Bound, Constructor, ConstructorOutput, Inject, constructor};
29    pub use crate::{CastFrom, Dependency, ResolveError, Resolver, Service};
30}
31
32/// How long a resolved instance is reused.
33#[derive(Debug, Clone, Copy, PartialEq, Eq)]
34pub enum Lifetime {
35    /// One instance for the life of the provider.
36    Singleton,
37    /// One instance per scope.
38    Scoped,
39    /// A new instance on every resolution.
40    Transient,
41}