"""
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: 4
- managed scopes: action:4, step:5
- graph has async specs: False
- cleanup support enabled in graph: False
- provider count: 2
- cached provider count: 2
- thread lock count: 2
- async lock count: 0
- provider slots: 2, 3

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


import threading


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_4: Any = 4
_scope_obj_5: Any = 5
_dep_2_type: Any = _MISSING_PROVIDER
_provider_2: Any = _MISSING_PROVIDER
_dep_3_type: Any = _MISSING_PROVIDER
_provider_3: Any = _MISSING_PROVIDER


_dep_2_thread_lock = threading.Lock()
_dep_3_thread_lock = threading.Lock()

class RootResolver:

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

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



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


    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: False.
        """

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

    def enter_scope(
        self,
        scope: Any | None = None,
        *,
        context: Any | None = None,
    ) -> RootResolver | _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:
            return _StepResolver(
                self,
                context,
                self,
            )
        if scope is None:
            return _StepResolver(
                self,
                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: 2, 3.
        Dispatch uses identity checks against module-level `_dep_<slot>_type` globals.
        """

        # Fast path identity checks to avoid reflective dispatch.
        if dependency is _dep_2_type:
            return self.resolve_2()
        if dependency is _dep_3_type:
            return RootResolver.resolve_3(self)
        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:
                if slot == 2:
                    results.append(self.resolve_2())
                    continue
                if slot == 3:
                    results.append(self.resolve_3())
                    continue
                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: 2, 3.
        Dispatch uses identity checks against module-level `_dep_<slot>_type` globals.
        """

        # Fast path identity checks for asynchronous resolution.
        if dependency is _dep_2_type:
            return await self.aresolve_2()
        if dependency is _dep_3_type:
            return await RootResolver.aresolve_3(self)
        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:
                if slot == 2:
                    results.append(await self.aresolve_2())
                    continue
                if slot == 3:
                    results.append(await self.aresolve_3())
                    continue
                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)


    def resolve_2(self) -> Any:

        """
        Provider slot 2 resolver (sync method).

        Returns: tests.unit.internal.test_resolver_assembly_expected_output._SnapshotActionRootActionService
        Provider spec kind: concrete_type
        Provider target: tests.unit.internal.test_resolver_assembly_expected_output._SnapshotActionRootActionService
        Declared scope: action (level 4)
        Declared lifetime: singleton
        Cache policy: cached
        Cache owner scope: 4
        Declared lock mode: auto
        Effective lock mode: thread
        Sync path thread lock: True
        Async path async lock: False
        Provider declared async: False
        Graph requires async: False
        Cleanup callbacks required: False
        Resolver class handling this call: RootResolver
        Dependency wiring: none
        Behavior: Builds the provider value in this resolver, enforcing scope guards and cache policy.
        """

        cached_value = self._cache_2
        if cached_value is not _MISSING_CACHE:
            return cached_value
        with _dep_2_thread_lock:
            if (cached_value := self._cache_2) is not _MISSING_CACHE:
                return cached_value
            value = _provider_2()
            self._cache_2 = value
            self.resolve_2 = lambda: value  # type: ignore[method-assign]

            async def _cached() -> Any:
                return value

            self.aresolve_2 = _cached  # type: ignore[method-assign]
            return value

    async def aresolve_2(self) -> Any:

        """
        Provider slot 2 resolver (async method).

        Returns: tests.unit.internal.test_resolver_assembly_expected_output._SnapshotActionRootActionService
        Provider spec kind: concrete_type
        Provider target: tests.unit.internal.test_resolver_assembly_expected_output._SnapshotActionRootActionService
        Declared scope: action (level 4)
        Declared lifetime: singleton
        Cache policy: cached
        Cache owner scope: 4
        Declared lock mode: auto
        Effective lock mode: thread
        Sync path thread lock: True
        Async path async lock: False
        Provider declared async: False
        Graph requires async: False
        Cleanup callbacks required: False
        Resolver class handling this call: RootResolver
        Dependency wiring: none
        Behavior: Async variant delegates to sync resolution because this provider graph does not require awaitable operations.
        """

        return self.resolve_2()

    def resolve_3(self) -> Any:

        """
        Provider slot 3 resolver (sync method).

        Returns: tests.unit.internal.test_resolver_assembly_expected_output._SnapshotActionRootStepService
        Provider spec kind: concrete_type
        Provider target: tests.unit.internal.test_resolver_assembly_expected_output._SnapshotActionRootStepService
        Declared scope: step (level 5)
        Declared lifetime: scoped
        Cache policy: cached
        Cache owner scope: 5
        Declared lock mode: auto
        Effective lock mode: thread
        Sync path thread lock: True
        Async path async lock: False
        Provider declared async: False
        Graph requires async: False
        Cleanup callbacks required: False
        Resolver class handling this call: RootResolver
        Dependency wiring: none
        Behavior: This resolver cannot access the provider yet because the required scope is deeper than the current resolver scope.
        """

        msg = "Provider slot 3 requires opened scope level 5."
        raise DIWireScopeMismatchError(msg)

    async def aresolve_3(self) -> Any:

        """
        Provider slot 3 resolver (async method).

        Returns: tests.unit.internal.test_resolver_assembly_expected_output._SnapshotActionRootStepService
        Provider spec kind: concrete_type
        Provider target: tests.unit.internal.test_resolver_assembly_expected_output._SnapshotActionRootStepService
        Declared scope: step (level 5)
        Declared lifetime: scoped
        Cache policy: cached
        Cache owner scope: 5
        Declared lock mode: auto
        Effective lock mode: thread
        Sync path thread lock: True
        Async path async lock: False
        Provider declared async: False
        Graph requires async: False
        Cleanup callbacks required: False
        Resolver class handling this call: RootResolver
        Dependency wiring: none
        Behavior: Async variant delegates to sync resolution because this provider graph does not require awaitable operations.
        """

        return self.resolve_3()


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: 2, 3.
    Providers declared in this exact scope: 3.
    """



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


    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: False.
        """

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

    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: 2, 3.
        Dispatch uses identity checks against module-level `_dep_<slot>_type` globals.
        """

        # Fast path identity checks to avoid reflective dispatch.
        if dependency is _dep_3_type:
            return _StepResolver.resolve_3(self)
        if dependency is _dep_2_type:
            return _StepResolver.resolve_2(self)
        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:
                if slot == 2:
                    results.append(self.resolve_2())
                    continue
                if slot == 3:
                    results.append(self.resolve_3())
                    continue
                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: 2, 3.
        Dispatch uses identity checks against module-level `_dep_<slot>_type` globals.
        """

        # Fast path identity checks for asynchronous resolution.
        if dependency is _dep_3_type:
            return await _StepResolver.aresolve_3(self)
        if dependency is _dep_2_type:
            return await _StepResolver.aresolve_2(self)
        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:
                if slot == 2:
                    results.append(await self.aresolve_2())
                    continue
                if slot == 3:
                    results.append(await self.aresolve_3())
                    continue
                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 resolve_2(self) -> Any:

        """
        Provider slot 2 resolver (sync method).

        Returns: tests.unit.internal.test_resolver_assembly_expected_output._SnapshotActionRootActionService
        Provider spec kind: concrete_type
        Provider target: tests.unit.internal.test_resolver_assembly_expected_output._SnapshotActionRootActionService
        Declared scope: action (level 4)
        Declared lifetime: singleton
        Cache policy: cached
        Cache owner scope: 4
        Declared lock mode: auto
        Effective lock mode: thread
        Sync path thread lock: True
        Async path async lock: False
        Provider declared async: False
        Graph requires async: False
        Cleanup callbacks required: False
        Resolver class handling this call: _StepResolver
        Dependency wiring: none
        Behavior: This resolver delegates to the cache owner resolver so scoped caching remains consistent across nested resolvers.
        """

        return self._root_resolver.resolve_2()

    async def aresolve_2(self) -> Any:

        """
        Provider slot 2 resolver (async method).

        Returns: tests.unit.internal.test_resolver_assembly_expected_output._SnapshotActionRootActionService
        Provider spec kind: concrete_type
        Provider target: tests.unit.internal.test_resolver_assembly_expected_output._SnapshotActionRootActionService
        Declared scope: action (level 4)
        Declared lifetime: singleton
        Cache policy: cached
        Cache owner scope: 4
        Declared lock mode: auto
        Effective lock mode: thread
        Sync path thread lock: True
        Async path async lock: False
        Provider declared async: False
        Graph requires async: False
        Cleanup callbacks required: False
        Resolver class handling this call: _StepResolver
        Dependency wiring: none
        Behavior: Async variant delegates to sync resolution because this provider graph does not require awaitable operations.
        """

        return self.resolve_2()

    def resolve_3(self) -> Any:

        """
        Provider slot 3 resolver (sync method).

        Returns: tests.unit.internal.test_resolver_assembly_expected_output._SnapshotActionRootStepService
        Provider spec kind: concrete_type
        Provider target: tests.unit.internal.test_resolver_assembly_expected_output._SnapshotActionRootStepService
        Declared scope: step (level 5)
        Declared lifetime: scoped
        Cache policy: cached
        Cache owner scope: 5
        Declared lock mode: auto
        Effective lock mode: thread
        Sync path thread lock: True
        Async path async lock: False
        Provider declared async: False
        Graph requires async: False
        Cleanup callbacks required: False
        Resolver class handling this call: _StepResolver
        Dependency wiring: none
        Behavior: Builds the provider value in this resolver, enforcing scope guards and cache policy.
        """

        cached_value = self._cache_3
        if cached_value is not _MISSING_CACHE:
            return cached_value
        with _dep_3_thread_lock:
            if (cached_value := self._cache_3) is not _MISSING_CACHE:
                return cached_value
            value = _provider_3()
            self._cache_3 = value
            return value

    async def aresolve_3(self) -> Any:

        """
        Provider slot 3 resolver (async method).

        Returns: tests.unit.internal.test_resolver_assembly_expected_output._SnapshotActionRootStepService
        Provider spec kind: concrete_type
        Provider target: tests.unit.internal.test_resolver_assembly_expected_output._SnapshotActionRootStepService
        Declared scope: step (level 5)
        Declared lifetime: scoped
        Cache policy: cached
        Cache owner scope: 5
        Declared lock mode: auto
        Effective lock mode: thread
        Sync path thread lock: True
        Async path async lock: False
        Provider declared async: False
        Graph requires async: False
        Cleanup callbacks required: False
        Resolver class handling this call: _StepResolver
        Dependency wiring: none
        Behavior: Async variant delegates to sync resolution because this provider graph does not require awaitable operations.
        """

        return self.resolve_3()

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: 2, 3.
    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]] = {}

    global _dep_2_type, _provider_2
    global _dep_3_type, _provider_3

    # --- Provider slot 2 bootstrap metadata ---
    # Read provider spec by stable slot id from registrations.
    registration_2 = registrations.get_by_slot(2)
    # Capture dependency identity token used by `resolve`/`aresolve` dispatch.
    _dep_2_type = registration_2.provides
    # Track dependency keys that are directly registered in this compiled graph.
    _dep_registered_keys.add(_dep_2_type)
    # Capture provider object (instance/type/factory/generator/context manager).
    _provider_2 = registration_2.concrete_type
    # Index provider slot for All[...] dependency dispatch.
    component_base_2 = component_base_key(_dep_2_type)
    base_key_2 = component_base_2
    if base_key_2 is None and not hasattr(_dep_2_type, '__metadata__'):
        base_key_2 = _dep_2_type
    if base_key_2 is not None:
        all_slots_by_key.setdefault(base_key_2, []).append(2)

    # --- Provider slot 3 bootstrap metadata ---
    # Read provider spec by stable slot id from registrations.
    registration_3 = registrations.get_by_slot(3)
    # Capture dependency identity token used by `resolve`/`aresolve` dispatch.
    _dep_3_type = registration_3.provides
    # Track dependency keys that are directly registered in this compiled graph.
    _dep_registered_keys.add(_dep_3_type)
    # Capture provider object (instance/type/factory/generator/context manager).
    _provider_3 = registration_3.concrete_type
    # Index provider slot for All[...] dependency dispatch.
    component_base_3 = component_base_key(_dep_3_type)
    base_key_3 = component_base_3
    if base_key_3 is None and not hasattr(_dep_3_type, '__metadata__'):
        base_key_3 = _dep_3_type
    if base_key_3 is not None:
        all_slots_by_key.setdefault(base_key_3, []).append(3)

    # 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()