Scopes

class diwire.ScopedContainer(_container: Any, _scope_id: _ScopeId)[source]

A context manager for scoped dependency resolution.

Supports both sync and async context managers: - with container.enter_scope() for sync usage - async with container.enter_scope() for async usage with proper async cleanup

Also supports imperative usage: - scope = container.enter_scope() to activate immediately - scope.close() or scope.aclose() to close explicitly - container.close() or container.aclose() to close all active scopes

resolve(key: Any) Any[source]

Resolve a service within this scope.

async aresolve(key: Any) Any[source]

Asynchronously resolve a service within this scope.

enter_scope(scope_name: str | None = None) ScopedContainer[source]

Start a nested scope.

close() None[source]

Explicitly close this scope (sync).

async aclose() None[source]

Explicitly close this scope (async).