pub struct ServiceCollection { /* private fields */ }Implementations§
Source§impl ServiceCollection
impl ServiceCollection
pub fn new() -> Self
pub fn singleton<T: ?Sized + Send + Sync + 'static>( self, f: impl Fn(&dyn IServiceResolver) -> Arc<T> + Send + Sync + 'static, ) -> Self
pub fn transient<T: ?Sized + Send + Sync + 'static>( self, f: impl Fn(&dyn IServiceResolver) -> Arc<T> + Send + Sync + 'static, ) -> Self
pub fn scoped<T: ?Sized + Send + Sync + 'static>( self, f: impl Fn(&dyn IServiceResolver) -> Arc<T> + Send + Sync + 'static, ) -> Self
Sourcepub fn keyed_singleton<T: ?Sized + Send + Sync + 'static>(
self,
k: impl Into<String>,
f: impl Fn(&dyn IServiceResolver) -> Arc<T> + Send + Sync + 'static,
) -> Self
pub fn keyed_singleton<T: ?Sized + Send + Sync + 'static>( self, k: impl Into<String>, f: impl Fn(&dyn IServiceResolver) -> Arc<T> + Send + Sync + 'static, ) -> Self
Register a keyed singleton service.
The key distinguishes multiple implementations of the same trait.
Use get_keyed::<T>(key) or try_get_keyed::<T>(key) to resolve.
Sourcepub fn keyed_transient<T: ?Sized + Send + Sync + 'static>(
self,
k: impl Into<String>,
f: impl Fn(&dyn IServiceResolver) -> Arc<T> + Send + Sync + 'static,
) -> Self
pub fn keyed_transient<T: ?Sized + Send + Sync + 'static>( self, k: impl Into<String>, f: impl Fn(&dyn IServiceResolver) -> Arc<T> + Send + Sync + 'static, ) -> Self
Register a keyed transient service (new instance each resolution).
Sourcepub fn keyed_scoped<T: ?Sized + Send + Sync + 'static>(
self,
k: impl Into<String>,
f: impl Fn(&dyn IServiceResolver) -> Arc<T> + Send + Sync + 'static,
) -> Self
pub fn keyed_scoped<T: ?Sized + Send + Sync + 'static>( self, k: impl Into<String>, f: impl Fn(&dyn IServiceResolver) -> Arc<T> + Send + Sync + 'static, ) -> Self
Register a keyed scoped service (shared within a scope).
Sourcepub fn async_singleton<T: ?Sized + Send + Sync + 'static>(
self,
f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static,
) -> Self
pub fn async_singleton<T: ?Sized + Send + Sync + 'static>( self, f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static, ) -> Self
Register an async singleton service (initialized once during build_async).
Sourcepub fn async_transient<T: ?Sized + Send + Sync + 'static>(
self,
f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static,
) -> Self
pub fn async_transient<T: ?Sized + Send + Sync + 'static>( self, f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static, ) -> Self
Register an async transient service (new async instance each resolution).
Sourcepub fn async_scoped<T: ?Sized + Send + Sync + 'static>(
self,
f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static,
) -> Self
pub fn async_scoped<T: ?Sized + Send + Sync + 'static>( self, f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static, ) -> Self
Register an async scoped service (shared within a scope).
Sourcepub fn async_keyed_singleton<T: ?Sized + Send + Sync + 'static>(
self,
k: impl Into<String>,
f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static,
) -> Self
pub fn async_keyed_singleton<T: ?Sized + Send + Sync + 'static>( self, k: impl Into<String>, f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static, ) -> Self
Register an async keyed singleton service.
Sourcepub fn async_keyed_transient<T: ?Sized + Send + Sync + 'static>(
self,
k: impl Into<String>,
f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static,
) -> Self
pub fn async_keyed_transient<T: ?Sized + Send + Sync + 'static>( self, k: impl Into<String>, f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static, ) -> Self
Register an async keyed transient service.
Sourcepub fn async_keyed_scoped<T: ?Sized + Send + Sync + 'static>(
self,
k: impl Into<String>,
f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static,
) -> Self
pub fn async_keyed_scoped<T: ?Sized + Send + Sync + 'static>( self, k: impl Into<String>, f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static, ) -> Self
Register an async keyed scoped service.
pub fn try_add<T: ?Sized + Send + Sync + 'static>( self, f: impl Fn(&dyn IServiceResolver) -> Arc<T> + Send + Sync + 'static, ) -> Self
pub fn add<T: ?Sized + Send + Sync + 'static>( self, lt: ServiceLifetime, f: impl Fn(&dyn IServiceResolver) -> Arc<T> + Send + Sync + 'static, ) -> Self
pub fn instance<T: Send + Sync + 'static>(self, v: Arc<T>) -> Self
pub fn singleton_value<T: Send + Sync + 'static>(self, v: T) -> Self
pub fn build(self) -> Result<Arc<ServiceProvider>, RdiError>
Sourcepub async fn build_async(self) -> Result<Arc<ServiceProvider>, RdiError>
pub async fn build_async(self) -> Result<Arc<ServiceProvider>, RdiError>
Build the provider, executing async factories for singleton services.
Async singleton factories are run during build and their results are cached as singleton instances. Async transient/scoped factories are stored for later resolution.
Returns Arc<ServiceProvider> so that provider_arc() works for
async resolution via get_async / get_keyed_async.
Use this instead of build when any service requires
async initialization (e.g., database connections, remote config).
Sourcepub fn from_injected() -> Self
pub fn from_injected() -> Self
Build a ServiceCollection from all #[rust_dix::inject] annotations
in the current binary (across all crates).