ResolverContext¶
- class diwire.ResolverContext[source]¶
Task/thread-safe context for resolver-bound injection and resolution.
- resolve(dependency)[source]¶
Resolve a dependency from the active resolver or fallback container.
- Parameters:
dependency – Dependency key to resolve.
- Raises:
DIWireResolverNotSetError – If no resolver is bound and no fallback container is configured.
- async aresolve(dependency)[source]¶
Asynchronously resolve a dependency from context or fallback.
- Parameters:
dependency – Dependency key to resolve.
- Raises:
DIWireResolverNotSetError – If no resolver is bound and no fallback container is configured.
- enter_scope(scope=None, *, context=None)[source]¶
Enter a child scope on the active resolver or fallback resolver.
- Parameters:
scope – Target scope to enter.
Nonekeeps the current scope.context – Optional context payload merged into the entered scope.
- Raises:
DIWireResolverNotSetError – If no resolver is bound and no fallback container is configured.
- inject(func='from_decorator', *, scope='infer', dependency_registration_policy='from_container', auto_open_scope=True)[source]¶
Wrap callables so
Injected[...]parameters resolve at invocation.Resolution precedence at call time is explicit
diwire_resolver, then an active context-bound resolver, then the configured fallback container when it is configured withuse_resolver_context=True.- Parameters:
func – Callable to wrap directly, or
"from_decorator"when used as@resolver_context.inject(...).scope – Explicit scope for wrapper generation, or
"infer"to infer from injected dependencies.dependency_registration_policy – Dependency autoregistration policy for wrapper generation, or
"from_container"to inherit the fallback container setting.auto_open_scope – Whether invocation should auto-enter scopes when needed. When
True(default), scope entry is attempted only when moving into a deeper target scope is valid and required. If the target scope is already open, no additional scope is entered. If the current resolver is already deeper than the target scope, no additional scope is entered and resolution proceeds from the current resolver (including its existing scope-context chain).
- Raises:
DIWireInvalidRegistrationError – If inject configuration values are invalid,
funcis not callable, or the callable uses reserved parameter names.DIWireResolverNotSetError – If invocation has no explicit resolver, no active context resolver, and no fallback container eligible for inject fallback.