pub struct ServiceCollection { /* private fields */ }Implementations§
Source§impl ServiceCollection
impl ServiceCollection
pub fn new() -> ServiceCollection
pub fn singleton<T>( self, f: impl Fn(&dyn IServiceResolver) -> Arc<T> + Send + Sync + 'static, ) -> ServiceCollection
pub fn transient<T>( self, f: impl Fn(&dyn IServiceResolver) -> Arc<T> + Send + Sync + 'static, ) -> ServiceCollection
pub fn scoped<T>( self, f: impl Fn(&dyn IServiceResolver) -> Arc<T> + Send + Sync + 'static, ) -> ServiceCollection
Sourcepub fn keyed_singleton<T>(
self,
k: impl Into<String>,
f: impl Fn(&dyn IServiceResolver) -> Arc<T> + Send + Sync + 'static,
) -> ServiceCollection
pub fn keyed_singleton<T>( self, k: impl Into<String>, f: impl Fn(&dyn IServiceResolver) -> Arc<T> + Send + Sync + 'static, ) -> ServiceCollection
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>(
self,
k: impl Into<String>,
f: impl Fn(&dyn IServiceResolver) -> Arc<T> + Send + Sync + 'static,
) -> ServiceCollection
pub fn keyed_transient<T>( self, k: impl Into<String>, f: impl Fn(&dyn IServiceResolver) -> Arc<T> + Send + Sync + 'static, ) -> ServiceCollection
Register a keyed transient service (new instance each resolution).
Sourcepub fn keyed_scoped<T>(
self,
k: impl Into<String>,
f: impl Fn(&dyn IServiceResolver) -> Arc<T> + Send + Sync + 'static,
) -> ServiceCollection
pub fn keyed_scoped<T>( self, k: impl Into<String>, f: impl Fn(&dyn IServiceResolver) -> Arc<T> + Send + Sync + 'static, ) -> ServiceCollection
Register a keyed scoped service (shared within a scope).
Sourcepub fn async_singleton<T>(
self,
f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static,
) -> ServiceCollection
pub fn async_singleton<T>( self, f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static, ) -> ServiceCollection
Register an async singleton service (initialized once during build_async).
Sourcepub fn async_transient<T>(
self,
f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static,
) -> ServiceCollection
pub fn async_transient<T>( self, f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static, ) -> ServiceCollection
Register an async transient service (new async instance each resolution).
Sourcepub fn async_scoped<T>(
self,
f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static,
) -> ServiceCollection
pub fn async_scoped<T>( self, f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static, ) -> ServiceCollection
Register an async scoped service (shared within a scope).
Sourcepub fn async_keyed_singleton<T>(
self,
k: impl Into<String>,
f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static,
) -> ServiceCollection
pub fn async_keyed_singleton<T>( self, k: impl Into<String>, f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static, ) -> ServiceCollection
Register an async keyed singleton service.
Sourcepub fn async_keyed_transient<T>(
self,
k: impl Into<String>,
f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static,
) -> ServiceCollection
pub fn async_keyed_transient<T>( self, k: impl Into<String>, f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static, ) -> ServiceCollection
Register an async keyed transient service.
Sourcepub fn async_keyed_scoped<T>(
self,
k: impl Into<String>,
f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static,
) -> ServiceCollection
pub fn async_keyed_scoped<T>( self, k: impl Into<String>, f: impl Fn(Arc<ServiceProvider>) -> Pin<Box<dyn Future<Output = Arc<T>> + Send>> + Send + Sync + 'static, ) -> ServiceCollection
Register an async keyed scoped service.
pub fn try_add<T>( self, f: impl Fn(&dyn IServiceResolver) -> Arc<T> + Send + Sync + 'static, ) -> ServiceCollection
pub fn add<T>( self, lt: ServiceLifetime, f: impl Fn(&dyn IServiceResolver) -> Arc<T> + Send + Sync + 'static, ) -> ServiceCollection
pub fn instance<T>(self, v: Arc<T>) -> ServiceCollection
pub fn singleton_value<T>(self, v: T) -> ServiceCollection
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() -> ServiceCollection
pub fn from_injected() -> ServiceCollection
Build a ServiceCollection from all #[rust_dix::inject] annotations
in the current binary (across all crates).
Trait Implementations§
Source§impl DbContextServiceCollectionExt for ServiceCollection
impl DbContextServiceCollectionExt for ServiceCollection
Source§fn add_dbcontext(
self,
configure: impl FnOnce(&mut DbContextOptionsBuilder) + Send + Sync + 'static,
) -> Self
fn add_dbcontext( self, configure: impl FnOnce(&mut DbContextOptionsBuilder) + Send + Sync + 'static, ) -> Self
DbContext as scoped with default key. Read moreSource§fn add_dbcontext_keyed(
self,
key: &str,
configure: impl FnOnce(&mut DbContextOptionsBuilder) + Send + Sync + 'static,
) -> Self
fn add_dbcontext_keyed( self, key: &str, configure: impl FnOnce(&mut DbContextOptionsBuilder) + Send + Sync + 'static, ) -> Self
DbContext as scoped. Read more