diff --git a/modern_di_grpc/main.py b/modern_di_grpc/main.py index 01d191e..4894343 100644 --- a/modern_di_grpc/main.py +++ b/modern_di_grpc/main.py @@ -42,7 +42,7 @@ def fetch_di_container() -> Container: def _ensure_context_provider(container: Container) -> None: # Register grpc_context_provider once (idempotent) so ServicerContext injects out of the box. - if container.providers_registry.find_provider(ServicerContext) is None: + if container.find_provider(ServicerContext) is None: container.add_providers(grpc_context_provider) diff --git a/pyproject.toml b/pyproject.toml index aaf5b69..38b778a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ classifiers = [ dependencies = [ # The committed test stubs under tests/protos refuse to import below 1.82.1. "grpcio>=1.82.1,<2", - "modern-di>=3.1,<4", + "modern-di>=4,<5", ] version = "0" diff --git a/tests/dependencies.py b/tests/dependencies.py index cc2a05d..92fd484 100644 --- a/tests/dependencies.py +++ b/tests/dependencies.py @@ -24,8 +24,7 @@ class ContextReader: def _make_context_reader(context: ServicerContext | None = None) -> ContextReader: - # `context` is wired from grpc_context_provider (ContextProvider(ServicerContext, REQUEST)); - # the `| None = None` default lets it construct at validate time when no context is set. + # The default applies only when no DIInterceptor has registered grpc_context_provider on the container. return ContextReader(peer=context.peer() if context is not None else "no-context") diff --git a/tests/test_inject.py b/tests/test_inject.py index b2488b5..5c37377 100644 --- a/tests/test_inject.py +++ b/tests/test_inject.py @@ -189,7 +189,7 @@ def behavior(_request: object, _context: ServicerContext) -> str: def test_di_interceptor_registers_context_provider_idempotently() -> None: container = Container(groups=[Dependencies]) DIInterceptor(container) - assert container.providers_registry.find_provider(ServicerContext) is not None + assert container.find_provider(ServicerContext) is not None # Second construction on the same container must hit the idempotent-skip branch, not # try (and fail) to register grpc_context_provider a second time. DIInterceptor(container)