ServiceCollection
Collection of service descriptors provided during configuration.
environment
property
Provide information about the hosting environment an application is running.
settings
property
Collection of settings providers for the application to compose.
add_auto_activated_keyed_singleton
add_auto_activated_keyed_singleton(
service_key: TKey | None, service_type: type[TService]
) -> None
add_auto_activated_keyed_singleton(
service_key: TKey | None,
service_type: type[TService],
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
AsyncGenerator[TService],
],
) -> None
add_auto_activated_keyed_singleton(
service_key: TKey | None,
service_type: type[TService],
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
Generator[TService],
],
) -> None
add_auto_activated_keyed_singleton(
service_key: TKey | None,
service_type: type[TService],
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
Awaitable[TService],
],
) -> None
add_auto_activated_keyed_singleton(
service_key: TKey | None,
service_type: type[TService],
implementation_factory: Callable[
[TKey | None, *TFactoryParameter], TService
],
) -> None
add_auto_activated_keyed_singleton(
service_key: TKey | None,
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
AsyncGenerator[TService],
],
) -> None
add_auto_activated_keyed_singleton(
service_key: TKey | None,
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
Generator[TService],
],
) -> None
add_auto_activated_keyed_singleton(
service_key: TKey | None,
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
Awaitable[TService],
],
) -> None
add_auto_activated_keyed_singleton(
service_key: TKey | None,
implementation_factory: Callable[
[TKey | None, *TFactoryParameter], TService
],
) -> None
Add an auto-activated keyed singleton service.
An auto-activated keyed singleton service is instantiated when the service provider is built (eagerly), rather than when it's first requested (lazily).
add_auto_activated_singleton
add_auto_activated_singleton(
service_type: type[TService],
implementation_factory: Callable[
..., AsyncGenerator[TService]
],
) -> None
add_auto_activated_singleton(
service_type: type[TService],
implementation_factory: Callable[
..., Generator[TService]
],
) -> None
add_auto_activated_singleton(
service_type: type[TService],
implementation_factory: Callable[
..., Awaitable[TService]
],
) -> None
add_auto_activated_singleton(
service_type: type[TService],
implementation_factory: Callable[..., TService],
) -> None
add_auto_activated_singleton(
implementation_factory: Callable[
..., AsyncGenerator[TService]
],
) -> None
add_auto_activated_singleton(
implementation_factory: Callable[
..., Generator[TService]
],
) -> None
Add an auto-activated singleton service.
An auto-activated singleton service is instantiated when the service provider is built (eagerly), rather than when it's first requested (lazily).
add_keyed_scoped
add_keyed_scoped(
service_key: TKey | None,
service_type: type[TService],
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
AsyncGenerator[TService],
],
) -> None
add_keyed_scoped(
service_key: TKey | None,
service_type: type[TService],
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
Generator[TService],
],
) -> None
add_keyed_scoped(
service_key: TKey | None,
service_type: type[TService],
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
Awaitable[TService],
],
) -> None
add_keyed_scoped(
service_key: TKey | None,
service_type: type[TService],
implementation_factory: Callable[
[TKey | None, *TFactoryParameter], TService
],
) -> None
add_keyed_scoped(
service_key: TKey | None,
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
AsyncGenerator[TService],
],
) -> None
add_keyed_scoped(
service_key: TKey | None,
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
Generator[TService],
],
) -> None
add_keyed_scoped(
service_key: TKey | None,
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
Awaitable[TService],
],
) -> None
Add a keyed scoped service.
add_keyed_singleton
add_keyed_singleton(
service_key: TKey | None,
service_type: type[TService],
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
AsyncGenerator[TService],
],
) -> None
add_keyed_singleton(
service_key: TKey | None,
service_type: type[TService],
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
Generator[TService],
],
) -> None
add_keyed_singleton(
service_key: TKey | None,
service_type: type[TService],
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
Awaitable[TService],
],
) -> None
add_keyed_singleton(
service_key: TKey | None,
service_type: type[TService],
implementation_factory: Callable[
[TKey | None, *TFactoryParameter], TService
],
) -> None
add_keyed_singleton(
service_key: TKey | None,
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
AsyncGenerator[TService],
],
) -> None
add_keyed_singleton(
service_key: TKey | None,
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
Generator[TService],
],
) -> None
add_keyed_singleton(
service_key: TKey | None,
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
Awaitable[TService],
],
) -> None
add_keyed_singleton(
service_key: TKey | None,
implementation_factory: Callable[
[TKey | None, *TFactoryParameter], TService
],
) -> None
Add a keyed singleton service.
add_keyed_transient
add_keyed_transient(
service_key: TKey | None,
service_type: type[TService],
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
AsyncGenerator[TService],
],
) -> None
add_keyed_transient(
service_key: TKey | None,
service_type: type[TService],
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
Generator[TService],
],
) -> None
add_keyed_transient(
service_key: TKey | None,
service_type: type[TService],
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
Awaitable[TService],
],
) -> None
add_keyed_transient(
service_key: TKey | None,
service_type: type[TService],
implementation_factory: Callable[
[TKey | None, *TFactoryParameter], TService
],
) -> None
add_keyed_transient(
service_key: TKey | None,
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
AsyncGenerator[TService],
],
) -> None
add_keyed_transient(
service_key: TKey | None,
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
Generator[TService],
],
) -> None
add_keyed_transient(
service_key: TKey | None,
implementation_factory: Callable[
[TKey | None, *TFactoryParameter],
Awaitable[TService],
],
) -> None
Add a keyed transient service.
add_scoped
add_scoped(
service_type: type[TService],
implementation_factory: Callable[
..., AsyncGenerator[TService]
],
) -> None
add_scoped(
service_type: type[TService],
implementation_factory: Callable[
..., Generator[TService]
],
) -> None
add_scoped(
service_type: type[TService],
implementation_factory: Callable[
..., Awaitable[TService]
],
) -> None
Add a scoped service.
add_settings
Add a settings model as a singleton service.
add_singleton
add_singleton(
service_type: type[TService],
implementation_factory: Callable[
..., AsyncGenerator[TService]
],
) -> None
add_singleton(
service_type: type[TService],
implementation_factory: Callable[
..., Generator[TService]
],
) -> None
add_singleton(
service_type: type[TService],
implementation_factory: Callable[
..., Awaitable[TService]
],
) -> None
Add a singleton service.
add_sync_sqlmodel
Add synchronous SQLModel services.
add_transient
add_transient(
service_type: type[TService],
implementation_factory: Callable[
..., AsyncGenerator[TService]
],
) -> None
add_transient(
service_type: type[TService],
implementation_factory: Callable[
..., Generator[TService]
],
) -> None
add_transient(
service_type: type[TService],
implementation_factory: Callable[
..., Awaitable[TService]
],
) -> None
Add a transient service.
build_service_provider
build_service_provider(
validate_scopes: bool = False,
validate_on_build: bool = True,
) -> ServiceProvider
Create a :class:ServiceProvider containing services from the this :class:ServiceCollection.
configure_fastapi
Configure the FastAPI application to use dependency injection using the services from this service collection.
enable_keyed_singleton_auto_activation
Mark a registered keyed singleton service as auto-activated.
An auto-activated keyed singleton service is instantiated when the service provider is built (eagerly), rather than when it's first requested (lazily).