Skip to content

Commit e585e79

Browse files
authored
chore: adopt modern-di 2.25 integration seams (#30)
Replace the providers_registry reach-in with container.add_providers(), and the isinstance-on-AbstractProvider dispatch in _Dependency.__call__ with container.resolve_dependency() — same semantics, less surface touched. Bump the modern-di floor to >=2.25.0,<3.
1 parent 377364b commit e585e79

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

modern_di_litestar/main.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def __init__(self, container: Container, autowired_groups: list[type[Group]] | N
6262
self.groups = autowired_groups or []
6363

6464
def on_app_init(self, app_config: AppConfig) -> AppConfig:
65-
self.container.providers_registry.add_providers(*_CONNECTION_PROVIDERS)
65+
self.container.add_providers(*_CONNECTION_PROVIDERS)
6666
app_config.state.di_container = self.container
6767
app_config.dependencies["di_container"] = Provide(build_di_container)
6868
app_config.dependencies.update(_autowired_dependencies(self.groups, existing=app_config.dependencies))
@@ -91,10 +91,8 @@ async def build_di_container(
9191
class _Dependency(typing.Generic[T_co]):
9292
dependency: providers.AbstractProvider[T_co] | type[T_co]
9393

94-
async def __call__(self, di_container: NamedDependency[SkipValidation[Container]]) -> T_co | None:
95-
if isinstance(self.dependency, providers.AbstractProvider):
96-
return di_container.resolve_provider(self.dependency)
97-
return di_container.resolve(dependency_type=self.dependency)
94+
async def __call__(self, di_container: NamedDependency[SkipValidation[Container]]) -> T_co:
95+
return di_container.resolve_dependency(self.dependency)
9896

9997

10098
def FromDI(dependency: providers.AbstractProvider[T_co] | type[T_co]) -> Provide: # noqa: N802

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ classifiers = [
1717
"Typing :: Typed",
1818
"Topic :: Software Development :: Libraries",
1919
]
20-
dependencies = ["litestar>=2.23,<3", "modern-di>=2.21.0,<3"]
20+
dependencies = ["litestar>=2.23,<3", "modern-di>=2.25.0,<3"]
2121
version = "0"
2222

2323
[project.urls]

0 commit comments

Comments
 (0)