Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions modern_di/providers/context_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class ContextProvider(AbstractProvider[types.T_co]):
__slots__ = [*AbstractProvider.BASE_SLOTS]
__slots__ = [*AbstractProvider.BASE_SLOTS, "_context_type"]

def __init__(
self,
Expand All @@ -20,10 +20,11 @@ def __init__(
bound_type: type | None = types.UNSET, # type: ignore[assignment]
) -> None:
super().__init__(scope=scope, bound_type=bound_type if bound_type != types.UNSET else context_type)
self._context_type = context_type

def validate(self, container: "Container") -> dict[str, typing.Any]: # noqa: ARG002
return {"bound_type": self.bound_type, "self": self}

def resolve(self, container: "Container") -> types.T_co | None:
container = container.find_container(self.scope)
return container.context_registry.find_context(typing.cast(type[types.T_co], self.bound_type))
return container.context_registry.find_context(typing.cast(type[types.T_co], self._context_type))
Loading