ServiceProvider
Bases: BaseServiceProvider, AbstractAsyncContextManager['ServiceProvider']
Provider that resolves services.
is_fully_initialized
property
Indicate whether the provider is fully initialized (useful for Jupyter notebooks, which don't work well with context managers).
create_scope
Create a new :class:ServiceScope that can be used to resolve scoped services.
get_keyed_service
async
Get service of type TService or return None.
get_keyed_services
async
get_keyed_services(
service_key: object | None, service_type: type[TService]
) -> Sequence[TService]
Get all services of type TService.
get_overridden_call_site
Retrieve the override call site for a given identifier if present.
get_required_keyed_service
async
Get service of type TService or raise an error.
get_required_service
async
Get service of type TService or raise :class:NoServiceRegisteredError.
get_service
async
Get service of type TService or return None.
get_services
async
Get all services of type TService.
override_keyed_service
override_keyed_service(
service_key: object | None,
service_type: type,
implementation_instance: object | None,
) -> Generator[None]
Override a keyed service registration within the context manager scope.
It can be used to temporarily replace a service for testing specific scenarios. Don't use it in production.