pub trait DbContextServiceCollectionExt {
// Required methods
fn add_dbcontext(
self,
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;
}Expand description
Adds add_dbcontext and add_dbcontext_keyed to rust_dix::ServiceCollection.
Required Methods§
Sourcefn 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
Registers a DbContext as scoped with default key.
The closure receives a DbContextOptionsBuilder for provider
configuration. Resolve via get_owned::<DbContext>() for idiomatic
&mut self access, or get::<DbContext>() for shared Arc access
within a scope.
Sourcefn 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
Registers a keyed DbContext as scoped.
Use this when you need multiple database connections in the same
application. Each key identifies a distinct DbContext instance
with its own provider and interceptors. Resolve via
get_keyed_owned::<DbContext>("key") (owned) or
get_keyed::<DbContext>("key") (shared Arc).
§Example
ⓘ
.add_dbcontext_keyed("logs", |options| {
options.use_sqlite("logs.db");
})Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".