@@ -31,6 +31,41 @@ child container should open at. This is the single source of the
3131kind → scope mapping; ` setup_di ` registers them and the child-container builder
3232dispatches off them.
3333
34+ <!-- invisible-code-block: python
35+ import dataclasses
36+ import types
37+ import typing
38+
39+ from modern_di import Container, Group, Scope, providers
40+
41+
42+ class _App:
43+ def __init__(self) -> None:
44+ self.state = types.SimpleNamespace()
45+
46+
47+ class _Request:
48+ def __init__(self, app: _App) -> None:
49+ self.app = app
50+
51+
52+ class _WebSocket:
53+ def __init__(self, app: _App) -> None:
54+ self.app = app
55+
56+
57+ myfw = types.SimpleNamespace(App=_App, Request=_Request, WebSocket=_WebSocket, Depends=lambda dependency: dependency)
58+ HTTPConnection = _Request
59+ T_co = typing.TypeVar("T_co", covariant=True)
60+
61+
62+ class MyService: ...
63+
64+
65+ class Dependencies(Group):
66+ service = providers.Factory(MyService, scope=Scope.REQUEST)
67+ -->
68+
3469``` python
3570from modern_di import Scope, providers
3671
@@ -168,6 +203,18 @@ def FromDI(dependency: providers.AbstractProvider[T_co] | type[T_co]) -> T_co:
168203 return typing.cast(T_co, myfw.Depends(Dependency(integrations.Marker(dependency))))
169204```
170205
206+ <!-- invisible-code-block: python
207+ app = myfw.App()
208+ setup_di(app, Container(groups=[Dependencies]))
209+ request = myfw.Request(app)
210+ builder = build_di_container(request)
211+ request_container = await anext(builder)
212+ assert request_container.scope is Scope.REQUEST
213+ assert request_container.resolve(myfw.Request) is request
214+ assert isinstance(await FromDI(Dependencies.service)(request_container), MyService)
215+ await builder.aclose()
216+ -->
217+
171218` Marker.resolve(container) ` is a single call, invariant across every
172219integration and both modes: it hands the wrapped provider-or-type to
173220` container.resolve_dependency ` , which routes to ` resolve_provider ` /` resolve `
0 commit comments