"""
Generated DI resolver module.

Generated by: diwire._internal.resolvers.assembly.renderer.ResolversAssemblyRenderer.get_providers_code
diwire version used for generation: 0.1.0.post109.dev0+cab17f0

Generation configuration:
- root scope level: 1
- managed scopes: app:1, session:2, request:3, action:4, step:5
- graph has async specs: False
- cleanup support enabled in graph: False
- provider count: 0
- cached provider count: 0
- thread lock count: 0
- async lock count: 0
- provider slots: none

Examples:
>>> root = build_root_resolver(registrations)
>>> service = root.resolve(SomeService)
>>> async_service = await root.aresolve(SomeAsyncService)
>>> request_scope = root.enter_scope()
>>> scoped_service = request_scope.resolve(RequestScopedService)
"""

from __future__ import annotations



from types import TracebackType
from typing import Any, NoReturn

from diwire.exceptions import (
    DIWireAsyncDependencyInSyncContextError,
    DIWireDependencyNotRegisteredError,
    DIWireScopeMismatchError,
)
from diwire._internal.markers import (
    is_async_provider_annotation,
    is_all_annotation,
    component_base_key,
    is_from_context_annotation,
    is_maybe_annotation,
    is_provider_annotation,
    strip_all_annotation,
    strip_from_context_annotation,
    strip_maybe_annotation,
    strip_provider_annotation,
)
from diwire._internal.providers import ProvidersRegistrations

_MISSING_RESOLVER: Any = object()
_MISSING_CACHE: Any = object()
_MISSING_PROVIDER: Any = object()
_all_slots_by_key: dict[Any, tuple[int, ...]] = {}
_dep_registered_keys: set[Any] = set()

_scope_obj_1: Any = 1
_scope_obj_2: Any = 2
_scope_obj_3: Any = 3
_scope_obj_4: Any = 4
_scope_obj_5: Any = 5

class RootResolver:

    """
    Generated resolver for scope 'app' (level 1).

    This class is generated and optimized for direct slot-based dependency resolution.
    All visible provider slots: none.
    Providers declared in this exact scope: none.
    """



    __slots__ = (
        "_root_resolver",
        "_context",
        "_parent_context_resolver",
        "__dict__",
        "_owned_scope_resolvers",
        "_scope_resolver_2",
        "_scope_resolver_3",
        "_scope_resolver_4",
        "_scope_resolver_5",
    )


    def __init__(
        self,
        context: Any | None = None,
        parent_context_resolver: Any = None,
    ) -> None:

        """
        Initialize resolver state for the current scope.

        The constructor wires scope ancestry references, cache slots, and optional cleanup state.
        Root scope class: RootResolver.
        Stateless scope reuse enabled: True.
        """

        self._root_resolver = self
        self._context = context
        self._parent_context_resolver = parent_context_resolver
        self._owned_scope_resolvers: tuple[Any, ...] = ()
        self._scope_resolver_2 = _SessionResolver(self._root_resolver)
        self._scope_resolver_3 = _RequestResolver(self._root_resolver)
        self._scope_resolver_4 = _ActionResolver(self._root_resolver)
        self._scope_resolver_5 = _StepResolver(self._root_resolver)

    def enter_scope(
        self,
        scope: Any | None = None,
        *,
        context: Any | None = None,
    ) -> RootResolver | _SessionResolver | _RequestResolver | _ActionResolver | _StepResolver:

        """
        Open a deeper scope resolver from this resolver.

        Current scope: app:1.
        Allowed explicit transitions: session:2, request:3, action:4, step:5.
        Passing None follows the default transition for the scope graph.
        Optional context mapping is attached to the opened target scope.
        """

        if scope is _scope_obj_3 or scope == 3:
            if context is None and self._context is None and self._parent_context_resolver is None:
                return self._root_resolver._scope_resolver_3
            return _RequestResolver(
                self._root_resolver,
                context,
                self,
            )
        if scope is None:
            if context is None and self._context is None and self._parent_context_resolver is None:
                return self._root_resolver._scope_resolver_3
            return _RequestResolver(
                self._root_resolver,
                context,
                self,
            )
        target_scope_level = scope
        if target_scope_level is _scope_obj_1 or target_scope_level == 1:
            return self
        if target_scope_level <= 1:
            msg = f"Cannot enter scope level {target_scope_level} from level 1."
            raise DIWireScopeMismatchError(msg)
        if target_scope_level is _scope_obj_2 or target_scope_level == 2:
            if context is None and self._context is None and self._parent_context_resolver is None:
                return self._root_resolver._scope_resolver_2
            return _SessionResolver(
                self._root_resolver,
                context,
                self,
            )
        if target_scope_level is _scope_obj_4 or target_scope_level == 4:
            if context is None and self._context is None and self._parent_context_resolver is None:
                return self._root_resolver._scope_resolver_4
            return _ActionResolver(
                self._root_resolver,
                context,
                self,
            )
        if target_scope_level is _scope_obj_5 or target_scope_level == 5:
            if context is None and self._context is None and self._parent_context_resolver is None:
                return self._root_resolver._scope_resolver_5
            return _StepResolver(
                self._root_resolver,
                context,
                self,
            )
        msg = f"Scope level {target_scope_level} is not a valid next transition from level 1."
        raise DIWireScopeMismatchError(msg)

    def resolve(self, dependency: Any) -> Any:

        """
        Route a dependency token to a generated synchronous provider resolver method.

        Known provider slots: none.
        Dispatch uses identity checks against module-level `_dep_<slot>_type` globals.
        """

        # Fast path identity checks to avoid reflective dispatch.
        if is_maybe_annotation(dependency):
            inner = strip_maybe_annotation(dependency)
            if is_provider_annotation(inner):
                provider_inner = strip_provider_annotation(inner)
                if is_async_provider_annotation(inner):
                    return lambda: self.aresolve(provider_inner)
                return lambda: self.resolve(provider_inner)
            if is_from_context_annotation(inner):
                key = strip_from_context_annotation(inner)
                try:
                    return self._resolve_from_context(key)
                except DIWireDependencyNotRegisteredError:
                    return None
            if not self._is_registered_dependency(inner):
                return None
            return self.resolve(inner)
        if is_provider_annotation(dependency):
            inner = strip_provider_annotation(dependency)
            if is_async_provider_annotation(dependency):
                return lambda: self.aresolve(inner)
            return lambda: self.resolve(inner)
        if is_from_context_annotation(dependency):
            key = strip_from_context_annotation(dependency)
            return self._resolve_from_context(key)
        if is_all_annotation(dependency):
            inner = strip_all_annotation(dependency)
            slots = _all_slots_by_key.get(inner, ())
            if not slots:
                return ()
            results: list[Any] = []
            for slot in slots:
                msg = f"Dependency {dependency!r} is not registered."
                raise DIWireDependencyNotRegisteredError(msg)
            return tuple(results)
        # Any dependency not pre-bound in build_root_resolver is unknown here.
        msg = f"Dependency {dependency!r} is not registered."
        raise DIWireDependencyNotRegisteredError(msg)

    async def aresolve(self, dependency: Any) -> Any:

        """
        Route a dependency token to a generated asynchronous provider resolver method.

        Known provider slots: none.
        Dispatch uses identity checks against module-level `_dep_<slot>_type` globals.
        """

        # Fast path identity checks for asynchronous resolution.
        if is_maybe_annotation(dependency):
            inner = strip_maybe_annotation(dependency)
            if is_provider_annotation(inner):
                provider_inner = strip_provider_annotation(inner)
                if is_async_provider_annotation(inner):
                    return lambda: self.aresolve(provider_inner)
                return lambda: self.resolve(provider_inner)
            if is_from_context_annotation(inner):
                key = strip_from_context_annotation(inner)
                try:
                    return self._resolve_from_context(key)
                except DIWireDependencyNotRegisteredError:
                    return None
            if not self._is_registered_dependency(inner):
                return None
            return await self.aresolve(inner)
        if is_provider_annotation(dependency):
            inner = strip_provider_annotation(dependency)
            if is_async_provider_annotation(dependency):
                return lambda: self.aresolve(inner)
            return lambda: self.resolve(inner)
        if is_from_context_annotation(dependency):
            key = strip_from_context_annotation(dependency)
            return self._resolve_from_context(key)
        if is_all_annotation(dependency):
            inner = strip_all_annotation(dependency)
            slots = _all_slots_by_key.get(inner, ())
            if not slots:
                return ()
            results: list[Any] = []
            for slot in slots:
                msg = f"Dependency {dependency!r} is not registered."
                raise DIWireDependencyNotRegisteredError(msg)
            return tuple(results)
        # Any dependency not pre-bound in build_root_resolver is unknown here.
        msg = f"Dependency {dependency!r} is not registered."
        raise DIWireDependencyNotRegisteredError(msg)

    def _resolve_from_context(self, key: Any) -> Any:
        context = self._context
        if context is not None and key in context:
            return context[key]
        parent_context_resolver = self._parent_context_resolver
        while parent_context_resolver is not None:
            parent_context = parent_context_resolver._context
            if parent_context is not None and key in parent_context:
                return parent_context[key]
            parent_context_resolver = parent_context_resolver._parent_context_resolver
        msg = (f"Context value for {key!r} is not provided. Pass it via `enter_scope(..., context={...})` (or `diwire_context` for injected callables).")
        raise DIWireDependencyNotRegisteredError(msg)

    def _is_registered_dependency(self, dependency: Any) -> bool:
        return dependency in _dep_registered_keys

    def __enter__(self) -> RootResolver:
        return self

    def __exit__(
        self,
        exc_type: type[BaseException] | None,
        exc_value: BaseException | None,
        traceback: TracebackType | None,
    ) -> None:
        return None

    def close(
        self,
        exc_type: type[BaseException] | None = None,
        exc_value: BaseException | None = None,
        traceback: TracebackType | None = None,
    ) -> None:
        return self.__exit__(exc_type, exc_value, traceback)

    async def __aenter__(self) -> RootResolver:
        return self

    async def __aexit__(
        self,
        exc_type: type[BaseException] | None,
        exc_value: BaseException | None,
        traceback: TracebackType | None,
    ) -> None:
        return None

    async def aclose(
        self,
        exc_type: type[BaseException] | None = None,
        exc_value: BaseException | None = None,
        traceback: TracebackType | None = None,
    ) -> None:
        return await self.__aexit__(exc_type, exc_value, traceback)


class _SessionResolver:

    """
    Generated resolver for scope 'session' (level 2).

    This class is generated and optimized for direct slot-based dependency resolution.
    All visible provider slots: none.
    Providers declared in this exact scope: none.
    """



    __slots__ = (
        "_root_resolver",
        "_context",
        "_parent_context_resolver",
        "_owned_scope_resolvers",
    )


    def __init__(
        self,
        root_resolver: RootResolver,
        context: Any | None = None,
        parent_context_resolver: Any = None,
    ) -> None:

        """
        Initialize resolver state for the current scope.

        The constructor wires scope ancestry references, cache slots, and optional cleanup state.
        Root scope class: RootResolver.
        Stateless scope reuse enabled: True.
        """

        self._root_resolver = root_resolver
        self._context = context
        self._parent_context_resolver = parent_context_resolver
        self._owned_scope_resolvers: tuple[Any, ...] = ()

    def enter_scope(
        self,
        scope: Any | None = None,
        *,
        context: Any | None = None,
    ) -> _SessionResolver | _RequestResolver | _ActionResolver | _StepResolver:

        """
        Open a deeper scope resolver from this resolver.

        Current scope: session:2.
        Allowed explicit transitions: request:3, action:4, step:5.
        Passing None follows the default transition for the scope graph.
        Optional context mapping is attached to the opened target scope.
        """

        if scope is _scope_obj_3 or scope == 3:
            if context is None and self._context is None and self._parent_context_resolver is None:
                return self._root_resolver._scope_resolver_3
            return _RequestResolver(
                self._root_resolver,
                context,
                self,
            )
        if scope is None:
            if context is None and self._context is None and self._parent_context_resolver is None:
                return self._root_resolver._scope_resolver_3
            return _RequestResolver(
                self._root_resolver,
                context,
                self,
            )
        target_scope_level = scope
        if target_scope_level is _scope_obj_2 or target_scope_level == 2:
            return self
        if target_scope_level <= 2:
            msg = f"Cannot enter scope level {target_scope_level} from level 2."
            raise DIWireScopeMismatchError(msg)
        if target_scope_level is _scope_obj_4 or target_scope_level == 4:
            if context is None and self._context is None and self._parent_context_resolver is None:
                return self._root_resolver._scope_resolver_4
            return _ActionResolver(
                self._root_resolver,
                context,
                self,
            )
        if target_scope_level is _scope_obj_5 or target_scope_level == 5:
            if context is None and self._context is None and self._parent_context_resolver is None:
                return self._root_resolver._scope_resolver_5
            return _StepResolver(
                self._root_resolver,
                context,
                self,
            )
        msg = f"Scope level {target_scope_level} is not a valid next transition from level 2."
        raise DIWireScopeMismatchError(msg)

    def resolve(self, dependency: Any) -> Any:

        """
        Route a dependency token to a generated synchronous provider resolver method.

        Known provider slots: none.
        Dispatch uses identity checks against module-level `_dep_<slot>_type` globals.
        """

        # Fast path identity checks to avoid reflective dispatch.
        if is_maybe_annotation(dependency):
            inner = strip_maybe_annotation(dependency)
            if is_provider_annotation(inner):
                provider_inner = strip_provider_annotation(inner)
                if is_async_provider_annotation(inner):
                    return lambda: self.aresolve(provider_inner)
                return lambda: self.resolve(provider_inner)
            if is_from_context_annotation(inner):
                key = strip_from_context_annotation(inner)
                try:
                    return self._resolve_from_context(key)
                except DIWireDependencyNotRegisteredError:
                    return None
            if not self._is_registered_dependency(inner):
                return None
            return self.resolve(inner)
        if is_provider_annotation(dependency):
            inner = strip_provider_annotation(dependency)
            if is_async_provider_annotation(dependency):
                return lambda: self.aresolve(inner)
            return lambda: self.resolve(inner)
        if is_from_context_annotation(dependency):
            key = strip_from_context_annotation(dependency)
            return self._resolve_from_context(key)
        if is_all_annotation(dependency):
            inner = strip_all_annotation(dependency)
            slots = _all_slots_by_key.get(inner, ())
            if not slots:
                return ()
            results: list[Any] = []
            for slot in slots:
                msg = f"Dependency {dependency!r} is not registered."
                raise DIWireDependencyNotRegisteredError(msg)
            return tuple(results)
        # Any dependency not pre-bound in build_root_resolver is unknown here.
        msg = f"Dependency {dependency!r} is not registered."
        raise DIWireDependencyNotRegisteredError(msg)

    async def aresolve(self, dependency: Any) -> Any:

        """
        Route a dependency token to a generated asynchronous provider resolver method.

        Known provider slots: none.
        Dispatch uses identity checks against module-level `_dep_<slot>_type` globals.
        """

        # Fast path identity checks for asynchronous resolution.
        if is_maybe_annotation(dependency):
            inner = strip_maybe_annotation(dependency)
            if is_provider_annotation(inner):
                provider_inner = strip_provider_annotation(inner)
                if is_async_provider_annotation(inner):
                    return lambda: self.aresolve(provider_inner)
                return lambda: self.resolve(provider_inner)
            if is_from_context_annotation(inner):
                key = strip_from_context_annotation(inner)
                try:
                    return self._resolve_from_context(key)
                except DIWireDependencyNotRegisteredError:
                    return None
            if not self._is_registered_dependency(inner):
                return None
            return await self.aresolve(inner)
        if is_provider_annotation(dependency):
            inner = strip_provider_annotation(dependency)
            if is_async_provider_annotation(dependency):
                return lambda: self.aresolve(inner)
            return lambda: self.resolve(inner)
        if is_from_context_annotation(dependency):
            key = strip_from_context_annotation(dependency)
            return self._resolve_from_context(key)
        if is_all_annotation(dependency):
            inner = strip_all_annotation(dependency)
            slots = _all_slots_by_key.get(inner, ())
            if not slots:
                return ()
            results: list[Any] = []
            for slot in slots:
                msg = f"Dependency {dependency!r} is not registered."
                raise DIWireDependencyNotRegisteredError(msg)
            return tuple(results)
        # Any dependency not pre-bound in build_root_resolver is unknown here.
        msg = f"Dependency {dependency!r} is not registered."
        raise DIWireDependencyNotRegisteredError(msg)

    def _resolve_from_context(self, key: Any) -> Any:
        context = self._context
        if context is not None and key in context:
            return context[key]
        parent_context_resolver = self._parent_context_resolver
        while parent_context_resolver is not None:
            parent_context = parent_context_resolver._context
            if parent_context is not None and key in parent_context:
                return parent_context[key]
            parent_context_resolver = parent_context_resolver._parent_context_resolver
        msg = (f"Context value for {key!r} is not provided. Pass it via `enter_scope(..., context={...})` (or `diwire_context` for injected callables).")
        raise DIWireDependencyNotRegisteredError(msg)

    def _is_registered_dependency(self, dependency: Any) -> bool:
        return dependency in _dep_registered_keys

    def __enter__(self) -> _SessionResolver:
        return self

    def __exit__(
        self,
        exc_type: type[BaseException] | None,
        exc_value: BaseException | None,
        traceback: TracebackType | None,
    ) -> None:
        return None

    def close(
        self,
        exc_type: type[BaseException] | None = None,
        exc_value: BaseException | None = None,
        traceback: TracebackType | None = None,
    ) -> None:
        return self.__exit__(exc_type, exc_value, traceback)

    async def __aenter__(self) -> _SessionResolver:
        return self

    async def __aexit__(
        self,
        exc_type: type[BaseException] | None,
        exc_value: BaseException | None,
        traceback: TracebackType | None,
    ) -> None:
        return None

    async def aclose(
        self,
        exc_type: type[BaseException] | None = None,
        exc_value: BaseException | None = None,
        traceback: TracebackType | None = None,
    ) -> None:
        return await self.__aexit__(exc_type, exc_value, traceback)


class _RequestResolver:

    """
    Generated resolver for scope 'request' (level 3).

    This class is generated and optimized for direct slot-based dependency resolution.
    All visible provider slots: none.
    Providers declared in this exact scope: none.
    """



    __slots__ = (
        "_root_resolver",
        "_context",
        "_parent_context_resolver",
        "_owned_scope_resolvers",
    )


    def __init__(
        self,
        root_resolver: RootResolver,
        context: Any | None = None,
        parent_context_resolver: Any = None,
    ) -> None:

        """
        Initialize resolver state for the current scope.

        The constructor wires scope ancestry references, cache slots, and optional cleanup state.
        Root scope class: RootResolver.
        Stateless scope reuse enabled: True.
        """

        self._root_resolver = root_resolver
        self._context = context
        self._parent_context_resolver = parent_context_resolver
        self._owned_scope_resolvers: tuple[Any, ...] = ()

    def enter_scope(
        self,
        scope: Any | None = None,
        *,
        context: Any | None = None,
    ) -> _RequestResolver | _ActionResolver | _StepResolver:

        """
        Open a deeper scope resolver from this resolver.

        Current scope: request:3.
        Allowed explicit transitions: action:4, step:5.
        Passing None follows the default transition for the scope graph.
        Optional context mapping is attached to the opened target scope.
        """

        if scope is _scope_obj_4 or scope == 4:
            if context is None and self._context is None and self._parent_context_resolver is None:
                return self._root_resolver._scope_resolver_4
            return _ActionResolver(
                self._root_resolver,
                context,
                self,
            )
        if scope is None:
            if context is None and self._context is None and self._parent_context_resolver is None:
                return self._root_resolver._scope_resolver_4
            return _ActionResolver(
                self._root_resolver,
                context,
                self,
            )
        target_scope_level = scope
        if target_scope_level is _scope_obj_3 or target_scope_level == 3:
            return self
        if target_scope_level <= 3:
            msg = f"Cannot enter scope level {target_scope_level} from level 3."
            raise DIWireScopeMismatchError(msg)
        if target_scope_level is _scope_obj_5 or target_scope_level == 5:
            if context is None and self._context is None and self._parent_context_resolver is None:
                return self._root_resolver._scope_resolver_5
            return _StepResolver(
                self._root_resolver,
                context,
                self,
            )
        msg = f"Scope level {target_scope_level} is not a valid next transition from level 3."
        raise DIWireScopeMismatchError(msg)

    def resolve(self, dependency: Any) -> Any:

        """
        Route a dependency token to a generated synchronous provider resolver method.

        Known provider slots: none.
        Dispatch uses identity checks against module-level `_dep_<slot>_type` globals.
        """

        # Fast path identity checks to avoid reflective dispatch.
        if is_maybe_annotation(dependency):
            inner = strip_maybe_annotation(dependency)
            if is_provider_annotation(inner):
                provider_inner = strip_provider_annotation(inner)
                if is_async_provider_annotation(inner):
                    return lambda: self.aresolve(provider_inner)
                return lambda: self.resolve(provider_inner)
            if is_from_context_annotation(inner):
                key = strip_from_context_annotation(inner)
                try:
                    return self._resolve_from_context(key)
                except DIWireDependencyNotRegisteredError:
                    return None
            if not self._is_registered_dependency(inner):
                return None
            return self.resolve(inner)
        if is_provider_annotation(dependency):
            inner = strip_provider_annotation(dependency)
            if is_async_provider_annotation(dependency):
                return lambda: self.aresolve(inner)
            return lambda: self.resolve(inner)
        if is_from_context_annotation(dependency):
            key = strip_from_context_annotation(dependency)
            return self._resolve_from_context(key)
        if is_all_annotation(dependency):
            inner = strip_all_annotation(dependency)
            slots = _all_slots_by_key.get(inner, ())
            if not slots:
                return ()
            results: list[Any] = []
            for slot in slots:
                msg = f"Dependency {dependency!r} is not registered."
                raise DIWireDependencyNotRegisteredError(msg)
            return tuple(results)
        # Any dependency not pre-bound in build_root_resolver is unknown here.
        msg = f"Dependency {dependency!r} is not registered."
        raise DIWireDependencyNotRegisteredError(msg)

    async def aresolve(self, dependency: Any) -> Any:

        """
        Route a dependency token to a generated asynchronous provider resolver method.

        Known provider slots: none.
        Dispatch uses identity checks against module-level `_dep_<slot>_type` globals.
        """

        # Fast path identity checks for asynchronous resolution.
        if is_maybe_annotation(dependency):
            inner = strip_maybe_annotation(dependency)
            if is_provider_annotation(inner):
                provider_inner = strip_provider_annotation(inner)
                if is_async_provider_annotation(inner):
                    return lambda: self.aresolve(provider_inner)
                return lambda: self.resolve(provider_inner)
            if is_from_context_annotation(inner):
                key = strip_from_context_annotation(inner)
                try:
                    return self._resolve_from_context(key)
                except DIWireDependencyNotRegisteredError:
                    return None
            if not self._is_registered_dependency(inner):
                return None
            return await self.aresolve(inner)
        if is_provider_annotation(dependency):
            inner = strip_provider_annotation(dependency)
            if is_async_provider_annotation(dependency):
                return lambda: self.aresolve(inner)
            return lambda: self.resolve(inner)
        if is_from_context_annotation(dependency):
            key = strip_from_context_annotation(dependency)
            return self._resolve_from_context(key)
        if is_all_annotation(dependency):
            inner = strip_all_annotation(dependency)
            slots = _all_slots_by_key.get(inner, ())
            if not slots:
                return ()
            results: list[Any] = []
            for slot in slots:
                msg = f"Dependency {dependency!r} is not registered."
                raise DIWireDependencyNotRegisteredError(msg)
            return tuple(results)
        # Any dependency not pre-bound in build_root_resolver is unknown here.
        msg = f"Dependency {dependency!r} is not registered."
        raise DIWireDependencyNotRegisteredError(msg)

    def _resolve_from_context(self, key: Any) -> Any:
        context = self._context
        if context is not None and key in context:
            return context[key]
        parent_context_resolver = self._parent_context_resolver
        while parent_context_resolver is not None:
            parent_context = parent_context_resolver._context
            if parent_context is not None and key in parent_context:
                return parent_context[key]
            parent_context_resolver = parent_context_resolver._parent_context_resolver
        msg = (f"Context value for {key!r} is not provided. Pass it via `enter_scope(..., context={...})` (or `diwire_context` for injected callables).")
        raise DIWireDependencyNotRegisteredError(msg)

    def _is_registered_dependency(self, dependency: Any) -> bool:
        return dependency in _dep_registered_keys

    def __enter__(self) -> _RequestResolver:
        return self

    def __exit__(
        self,
        exc_type: type[BaseException] | None,
        exc_value: BaseException | None,
        traceback: TracebackType | None,
    ) -> None:
        return None

    def close(
        self,
        exc_type: type[BaseException] | None = None,
        exc_value: BaseException | None = None,
        traceback: TracebackType | None = None,
    ) -> None:
        return self.__exit__(exc_type, exc_value, traceback)

    async def __aenter__(self) -> _RequestResolver:
        return self

    async def __aexit__(
        self,
        exc_type: type[BaseException] | None,
        exc_value: BaseException | None,
        traceback: TracebackType | None,
    ) -> None:
        return None

    async def aclose(
        self,
        exc_type: type[BaseException] | None = None,
        exc_value: BaseException | None = None,
        traceback: TracebackType | None = None,
    ) -> None:
        return await self.__aexit__(exc_type, exc_value, traceback)


class _ActionResolver:

    """
    Generated resolver for scope 'action' (level 4).

    This class is generated and optimized for direct slot-based dependency resolution.
    All visible provider slots: none.
    Providers declared in this exact scope: none.
    """



    __slots__ = (
        "_root_resolver",
        "_context",
        "_parent_context_resolver",
        "_owned_scope_resolvers",
    )


    def __init__(
        self,
        root_resolver: RootResolver,
        context: Any | None = None,
        parent_context_resolver: Any = None,
    ) -> None:

        """
        Initialize resolver state for the current scope.

        The constructor wires scope ancestry references, cache slots, and optional cleanup state.
        Root scope class: RootResolver.
        Stateless scope reuse enabled: True.
        """

        self._root_resolver = root_resolver
        self._context = context
        self._parent_context_resolver = parent_context_resolver
        self._owned_scope_resolvers: tuple[Any, ...] = ()

    def enter_scope(
        self,
        scope: Any | None = None,
        *,
        context: Any | None = None,
    ) -> _ActionResolver | _StepResolver:

        """
        Open a deeper scope resolver from this resolver.

        Current scope: action:4.
        Allowed explicit transitions: step:5.
        Passing None follows the default transition for the scope graph.
        Optional context mapping is attached to the opened target scope.
        """

        if scope is _scope_obj_5 or scope == 5:
            if context is None and self._context is None and self._parent_context_resolver is None:
                return self._root_resolver._scope_resolver_5
            return _StepResolver(
                self._root_resolver,
                context,
                self,
            )
        if scope is None:
            if context is None and self._context is None and self._parent_context_resolver is None:
                return self._root_resolver._scope_resolver_5
            return _StepResolver(
                self._root_resolver,
                context,
                self,
            )
        target_scope_level = scope
        if target_scope_level is _scope_obj_4 or target_scope_level == 4:
            return self
        if target_scope_level <= 4:
            msg = f"Cannot enter scope level {target_scope_level} from level 4."
            raise DIWireScopeMismatchError(msg)
        msg = f"Scope level {target_scope_level} is not a valid next transition from level 4."
        raise DIWireScopeMismatchError(msg)

    def resolve(self, dependency: Any) -> Any:

        """
        Route a dependency token to a generated synchronous provider resolver method.

        Known provider slots: none.
        Dispatch uses identity checks against module-level `_dep_<slot>_type` globals.
        """

        # Fast path identity checks to avoid reflective dispatch.
        if is_maybe_annotation(dependency):
            inner = strip_maybe_annotation(dependency)
            if is_provider_annotation(inner):
                provider_inner = strip_provider_annotation(inner)
                if is_async_provider_annotation(inner):
                    return lambda: self.aresolve(provider_inner)
                return lambda: self.resolve(provider_inner)
            if is_from_context_annotation(inner):
                key = strip_from_context_annotation(inner)
                try:
                    return self._resolve_from_context(key)
                except DIWireDependencyNotRegisteredError:
                    return None
            if not self._is_registered_dependency(inner):
                return None
            return self.resolve(inner)
        if is_provider_annotation(dependency):
            inner = strip_provider_annotation(dependency)
            if is_async_provider_annotation(dependency):
                return lambda: self.aresolve(inner)
            return lambda: self.resolve(inner)
        if is_from_context_annotation(dependency):
            key = strip_from_context_annotation(dependency)
            return self._resolve_from_context(key)
        if is_all_annotation(dependency):
            inner = strip_all_annotation(dependency)
            slots = _all_slots_by_key.get(inner, ())
            if not slots:
                return ()
            results: list[Any] = []
            for slot in slots:
                msg = f"Dependency {dependency!r} is not registered."
                raise DIWireDependencyNotRegisteredError(msg)
            return tuple(results)
        # Any dependency not pre-bound in build_root_resolver is unknown here.
        msg = f"Dependency {dependency!r} is not registered."
        raise DIWireDependencyNotRegisteredError(msg)

    async def aresolve(self, dependency: Any) -> Any:

        """
        Route a dependency token to a generated asynchronous provider resolver method.

        Known provider slots: none.
        Dispatch uses identity checks against module-level `_dep_<slot>_type` globals.
        """

        # Fast path identity checks for asynchronous resolution.
        if is_maybe_annotation(dependency):
            inner = strip_maybe_annotation(dependency)
            if is_provider_annotation(inner):
                provider_inner = strip_provider_annotation(inner)
                if is_async_provider_annotation(inner):
                    return lambda: self.aresolve(provider_inner)
                return lambda: self.resolve(provider_inner)
            if is_from_context_annotation(inner):
                key = strip_from_context_annotation(inner)
                try:
                    return self._resolve_from_context(key)
                except DIWireDependencyNotRegisteredError:
                    return None
            if not self._is_registered_dependency(inner):
                return None
            return await self.aresolve(inner)
        if is_provider_annotation(dependency):
            inner = strip_provider_annotation(dependency)
            if is_async_provider_annotation(dependency):
                return lambda: self.aresolve(inner)
            return lambda: self.resolve(inner)
        if is_from_context_annotation(dependency):
            key = strip_from_context_annotation(dependency)
            return self._resolve_from_context(key)
        if is_all_annotation(dependency):
            inner = strip_all_annotation(dependency)
            slots = _all_slots_by_key.get(inner, ())
            if not slots:
                return ()
            results: list[Any] = []
            for slot in slots:
                msg = f"Dependency {dependency!r} is not registered."
                raise DIWireDependencyNotRegisteredError(msg)
            return tuple(results)
        # Any dependency not pre-bound in build_root_resolver is unknown here.
        msg = f"Dependency {dependency!r} is not registered."
        raise DIWireDependencyNotRegisteredError(msg)

    def _resolve_from_context(self, key: Any) -> Any:
        context = self._context
        if context is not None and key in context:
            return context[key]
        parent_context_resolver = self._parent_context_resolver
        while parent_context_resolver is not None:
            parent_context = parent_context_resolver._context
            if parent_context is not None and key in parent_context:
                return parent_context[key]
            parent_context_resolver = parent_context_resolver._parent_context_resolver
        msg = (f"Context value for {key!r} is not provided. Pass it via `enter_scope(..., context={...})` (or `diwire_context` for injected callables).")
        raise DIWireDependencyNotRegisteredError(msg)

    def _is_registered_dependency(self, dependency: Any) -> bool:
        return dependency in _dep_registered_keys

    def __enter__(self) -> _ActionResolver:
        return self

    def __exit__(
        self,
        exc_type: type[BaseException] | None,
        exc_value: BaseException | None,
        traceback: TracebackType | None,
    ) -> None:
        return None

    def close(
        self,
        exc_type: type[BaseException] | None = None,
        exc_value: BaseException | None = None,
        traceback: TracebackType | None = None,
    ) -> None:
        return self.__exit__(exc_type, exc_value, traceback)

    async def __aenter__(self) -> _ActionResolver:
        return self

    async def __aexit__(
        self,
        exc_type: type[BaseException] | None,
        exc_value: BaseException | None,
        traceback: TracebackType | None,
    ) -> None:
        return None

    async def aclose(
        self,
        exc_type: type[BaseException] | None = None,
        exc_value: BaseException | None = None,
        traceback: TracebackType | None = None,
    ) -> None:
        return await self.__aexit__(exc_type, exc_value, traceback)


class _StepResolver:

    """
    Generated resolver for scope 'step' (level 5).

    This class is generated and optimized for direct slot-based dependency resolution.
    All visible provider slots: none.
    Providers declared in this exact scope: none.
    """



    __slots__ = (
        "_root_resolver",
        "_context",
        "_parent_context_resolver",
        "_owned_scope_resolvers",
    )


    def __init__(
        self,
        root_resolver: RootResolver,
        context: Any | None = None,
        parent_context_resolver: Any = None,
    ) -> None:

        """
        Initialize resolver state for the current scope.

        The constructor wires scope ancestry references, cache slots, and optional cleanup state.
        Root scope class: RootResolver.
        Stateless scope reuse enabled: True.
        """

        self._root_resolver = root_resolver
        self._context = context
        self._parent_context_resolver = parent_context_resolver
        self._owned_scope_resolvers: tuple[Any, ...] = ()

    def enter_scope(
        self,
        scope: Any | None = None,
        *,
        context: Any | None = None,
    ) -> NoReturn:

        """
        Open a deeper scope resolver from this resolver.

        Current scope: step:5.
        Allowed explicit transitions: none.
        Passing None follows the default transition for the scope graph.
        Optional context mapping is attached to the opened target scope.
        """

        msg = "Cannot enter deeper scope from level 5."
        raise DIWireScopeMismatchError(msg)

    def resolve(self, dependency: Any) -> Any:

        """
        Route a dependency token to a generated synchronous provider resolver method.

        Known provider slots: none.
        Dispatch uses identity checks against module-level `_dep_<slot>_type` globals.
        """

        # Fast path identity checks to avoid reflective dispatch.
        if is_maybe_annotation(dependency):
            inner = strip_maybe_annotation(dependency)
            if is_provider_annotation(inner):
                provider_inner = strip_provider_annotation(inner)
                if is_async_provider_annotation(inner):
                    return lambda: self.aresolve(provider_inner)
                return lambda: self.resolve(provider_inner)
            if is_from_context_annotation(inner):
                key = strip_from_context_annotation(inner)
                try:
                    return self._resolve_from_context(key)
                except DIWireDependencyNotRegisteredError:
                    return None
            if not self._is_registered_dependency(inner):
                return None
            return self.resolve(inner)
        if is_provider_annotation(dependency):
            inner = strip_provider_annotation(dependency)
            if is_async_provider_annotation(dependency):
                return lambda: self.aresolve(inner)
            return lambda: self.resolve(inner)
        if is_from_context_annotation(dependency):
            key = strip_from_context_annotation(dependency)
            return self._resolve_from_context(key)
        if is_all_annotation(dependency):
            inner = strip_all_annotation(dependency)
            slots = _all_slots_by_key.get(inner, ())
            if not slots:
                return ()
            results: list[Any] = []
            for slot in slots:
                msg = f"Dependency {dependency!r} is not registered."
                raise DIWireDependencyNotRegisteredError(msg)
            return tuple(results)
        # Any dependency not pre-bound in build_root_resolver is unknown here.
        msg = f"Dependency {dependency!r} is not registered."
        raise DIWireDependencyNotRegisteredError(msg)

    async def aresolve(self, dependency: Any) -> Any:

        """
        Route a dependency token to a generated asynchronous provider resolver method.

        Known provider slots: none.
        Dispatch uses identity checks against module-level `_dep_<slot>_type` globals.
        """

        # Fast path identity checks for asynchronous resolution.
        if is_maybe_annotation(dependency):
            inner = strip_maybe_annotation(dependency)
            if is_provider_annotation(inner):
                provider_inner = strip_provider_annotation(inner)
                if is_async_provider_annotation(inner):
                    return lambda: self.aresolve(provider_inner)
                return lambda: self.resolve(provider_inner)
            if is_from_context_annotation(inner):
                key = strip_from_context_annotation(inner)
                try:
                    return self._resolve_from_context(key)
                except DIWireDependencyNotRegisteredError:
                    return None
            if not self._is_registered_dependency(inner):
                return None
            return await self.aresolve(inner)
        if is_provider_annotation(dependency):
            inner = strip_provider_annotation(dependency)
            if is_async_provider_annotation(dependency):
                return lambda: self.aresolve(inner)
            return lambda: self.resolve(inner)
        if is_from_context_annotation(dependency):
            key = strip_from_context_annotation(dependency)
            return self._resolve_from_context(key)
        if is_all_annotation(dependency):
            inner = strip_all_annotation(dependency)
            slots = _all_slots_by_key.get(inner, ())
            if not slots:
                return ()
            results: list[Any] = []
            for slot in slots:
                msg = f"Dependency {dependency!r} is not registered."
                raise DIWireDependencyNotRegisteredError(msg)
            return tuple(results)
        # Any dependency not pre-bound in build_root_resolver is unknown here.
        msg = f"Dependency {dependency!r} is not registered."
        raise DIWireDependencyNotRegisteredError(msg)

    def _resolve_from_context(self, key: Any) -> Any:
        context = self._context
        if context is not None and key in context:
            return context[key]
        parent_context_resolver = self._parent_context_resolver
        while parent_context_resolver is not None:
            parent_context = parent_context_resolver._context
            if parent_context is not None and key in parent_context:
                return parent_context[key]
            parent_context_resolver = parent_context_resolver._parent_context_resolver
        msg = (f"Context value for {key!r} is not provided. Pass it via `enter_scope(..., context={...})` (or `diwire_context` for injected callables).")
        raise DIWireDependencyNotRegisteredError(msg)

    def _is_registered_dependency(self, dependency: Any) -> bool:
        return dependency in _dep_registered_keys

    def __enter__(self) -> _StepResolver:
        return self

    def __exit__(
        self,
        exc_type: type[BaseException] | None,
        exc_value: BaseException | None,
        traceback: TracebackType | None,
    ) -> None:
        return None

    def close(
        self,
        exc_type: type[BaseException] | None = None,
        exc_value: BaseException | None = None,
        traceback: TracebackType | None = None,
    ) -> None:
        return self.__exit__(exc_type, exc_value, traceback)

    async def __aenter__(self) -> _StepResolver:
        return self

    async def __aexit__(
        self,
        exc_type: type[BaseException] | None,
        exc_value: BaseException | None,
        traceback: TracebackType | None,
    ) -> None:
        return None

    async def aclose(
        self,
        exc_type: type[BaseException] | None = None,
        exc_value: BaseException | None = None,
        traceback: TracebackType | None = None,
    ) -> None:
        return await self.__aexit__(exc_type, exc_value, traceback)

def build_root_resolver(
    registrations: ProvidersRegistrations,
    *,
    cleanup_enabled: bool = True,
) -> RootResolver:

    """
    Build and return the generated root resolver instance.

    This function rebinds module-level provider globals for the supplied registrations.
    Global rebinding makes `resolve_<slot>` methods run without registration lookups.
    Provider slots configured during bootstrap: none.
    Root resolver class: RootResolver.

    Examples:
    >>> root = build_root_resolver(registrations)
    >>> root.resolve(SomeService)
    >>> await root.aresolve(SomeAsyncService)
    >>> scoped = root.enter_scope()
    """

    # Bind module-level globals to this container registration snapshot.
    # This keeps hot paths in resolver methods free from dictionary lookups.
    global _all_slots_by_key
    global _dep_registered_keys

    # Rebuild All[...] indexes for collect-all dependency dispatch.
    _all_slots_by_key = {}
    _dep_registered_keys = set()
    all_slots_by_key: dict[Any, list[int]] = {}

    # No provider registrations are active for the selected root scope.

    # Freeze All[...] indexes for stable repr and to discourage mutation.
    _all_slots_by_key = {
        key: tuple(slots) for key, slots in all_slots_by_key.items()
    }

    # Construct a fresh root resolver configured with optional cleanup callbacks.
    return RootResolver()