Integration base¶
depi.integration is the contract every framework adapter is built on. It lives
in core and stays dependency-free. You only need this page if you are writing a
new adapter; for using the existing ones see Integrations.
An adapter subclasses BaseInjector and
implements setup(app) to open a ServiceScope per
request, bind it with set_current_scope, and dispose
it when the request ends.
BaseInjector
¶
BaseInjector(provider: ServiceProvider, param_name: str = 'provider', autowire: bool = False)
Bases: ABC
Base class for framework integrations.
Parameters:
-
provider(ServiceProvider) –the built ServiceProvider to resolve from.
-
param_name(str, default:'provider') –the keyword argument the request scope is passed as in the default (non-autowire) mode. Name it to taste --
containeris a common alternative. -
autowire(bool, default:False) –when True,
injectresolves registered types by annotation instead of passing the scope. Not supported by every integration; FastAPI rejects it outright.
Source code in packages/depi-core/depi/integration.py
create_scope
¶
create_scope() -> ServiceScope
current_scope
¶
current_scope() -> ServiceScope
Return the scope bound to the current request context.
Raises:
-
NoActiveScopeError–if setup(app) never ran, or this is called outside a request.
Source code in packages/depi-core/depi/integration.py
setup
abstractmethod
¶
inject
¶
Decorator handing the request scope to fn.
Default mode passes the scope as the param_name keyword argument.
With autowire=True, parameters annotated with registered types are
resolved and passed individually instead.
Uses functools.wraps, so it composes inside a decorator stack (route registration, auth, response handling) without losing the wrapped function's identity.
Source code in packages/depi-core/depi/integration.py
injectable_parameters
¶
injectable_parameters(fn: Callable, provider: ServiceProvider) -> Dict[str, type]
Map parameter name -> registered type for the parameters depi should supply.
Parameters the provider does not know about are left alone, because the web framework almost certainly owns them (URL converters, query arguments). That is why autowire cannot fail fast on an unresolvable annotation: from here, "unregistered" and "supplied by the framework" look identical.
Called once at decoration time, never per request.