pub struct Container { /* private fields */ }Expand description
Thread-safe DI container with monomorphized resolution via get::<T>().
Prefer register_singleton for services — no dyn factory on the hot path.
Implementations§
Source§impl Container
impl Container
pub fn new() -> Self
Sourcepub fn register<T: Send + Sync + 'static>(&self, descriptor: ProviderDescriptor)
pub fn register<T: Send + Sync + 'static>(&self, descriptor: ProviderDescriptor)
Register a provider descriptor (advanced / async factories).
Sourcepub fn register_singleton<T: Send + Sync + 'static>(&self, instance: Arc<T>)
pub fn register_singleton<T: Send + Sync + 'static>(&self, instance: Arc<T>)
Register a singleton directly (compile-time friendly, no factory trait object).
Sourcepub fn register_default<T: Default + Send + Sync + 'static>(&self)
pub fn register_default<T: Default + Send + Sync + 'static>(&self)
Register T: Default as a singleton (used by #[service] macro).
Sourcepub fn register_instance<T: Send + Sync + 'static>(&self, instance: Arc<T>)
pub fn register_instance<T: Send + Sync + 'static>(&self, instance: Arc<T>)
Register a pre-built singleton instance (alias).
Sourcepub fn get<T: Send + Sync + 'static>(&self) -> Result<Arc<T>, DiError>
pub fn get<T: Send + Sync + 'static>(&self) -> Result<Arc<T>, DiError>
Resolve type T — monomorphized at each call site (no runtime type name).
Sourcepub async fn get_async<T: Send + Sync + 'static>(
&self,
) -> Result<Arc<T>, DiError>
pub async fn get_async<T: Send + Sync + 'static>( &self, ) -> Result<Arc<T>, DiError>
Async resolution for providers with async factories.
pub fn request_scope(&self) -> RequestScope<'_>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Container
impl RefUnwindSafe for Container
impl Send for Container
impl Sync for Container
impl Unpin for Container
impl UnsafeUnpin for Container
impl UnwindSafe for Container
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more