modern-di-faststream 0.6.0__py3-none-any.whl → 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- modern_di_faststream/main.py +9 -8
- {modern_di_faststream-0.6.0.dist-info → modern_di_faststream-1.0.0.dist-info}/METADATA +3 -2
- modern_di_faststream-1.0.0.dist-info/RECORD +6 -0
- {modern_di_faststream-0.6.0.dist-info → modern_di_faststream-1.0.0.dist-info}/WHEEL +1 -1
- modern_di_faststream-0.6.0.dist-info/RECORD +0 -6
modern_di_faststream/main.py
CHANGED
|
@@ -7,7 +7,7 @@ import faststream
|
|
|
7
7
|
import modern_di
|
|
8
8
|
from faststream.asgi import AsgiFastStream
|
|
9
9
|
from faststream.types import DecodedMessage
|
|
10
|
-
from modern_di import AsyncContainer,
|
|
10
|
+
from modern_di import AsyncContainer, providers
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
T_co = typing.TypeVar("T_co", covariant=True)
|
|
@@ -65,15 +65,12 @@ def fetch_di_container(app_: faststream.FastStream | AsgiFastStream) -> AsyncCon
|
|
|
65
65
|
|
|
66
66
|
def setup_di(
|
|
67
67
|
app: faststream.FastStream | AsgiFastStream,
|
|
68
|
-
|
|
69
|
-
container: AsyncContainer | None = None,
|
|
68
|
+
container: AsyncContainer,
|
|
70
69
|
) -> AsyncContainer:
|
|
71
70
|
if not app.broker:
|
|
72
71
|
msg = "Broker must be defined to setup DI"
|
|
73
72
|
raise RuntimeError(msg)
|
|
74
73
|
|
|
75
|
-
if not container:
|
|
76
|
-
container = AsyncContainer(scope=scope)
|
|
77
74
|
app.context.set_global("di_container", container)
|
|
78
75
|
app.on_startup(container.enter)
|
|
79
76
|
app.after_shutdown(container.close)
|
|
@@ -83,12 +80,16 @@ def setup_di(
|
|
|
83
80
|
|
|
84
81
|
@dataclasses.dataclass(slots=True, frozen=True)
|
|
85
82
|
class Dependency(typing.Generic[T_co]):
|
|
86
|
-
dependency: providers.AbstractProvider[T_co]
|
|
83
|
+
dependency: providers.AbstractProvider[T_co] | type[T_co]
|
|
87
84
|
|
|
88
85
|
async def __call__(self, context: faststream.ContextRepo) -> T_co:
|
|
89
86
|
request_container: modern_di.AsyncContainer = context.get("request_container")
|
|
90
|
-
|
|
87
|
+
if isinstance(self.dependency, providers.AbstractProvider):
|
|
88
|
+
return await request_container.resolve_provider(self.dependency)
|
|
89
|
+
return await request_container.resolve(dependency_type=self.dependency)
|
|
91
90
|
|
|
92
91
|
|
|
93
|
-
def FromDI(
|
|
92
|
+
def FromDI( # noqa: N802
|
|
93
|
+
dependency: providers.AbstractProvider[T_co] | type[T_co], *, use_cache: bool = True, cast: bool = False
|
|
94
|
+
) -> T_co:
|
|
94
95
|
return typing.cast(T_co, faststream.Depends(dependency=Dependency(dependency), use_cache=use_cache, cast=cast))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: modern-di-faststream
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 1.0.0
|
|
4
4
|
Summary: Modern-DI integration for FastStream
|
|
5
5
|
Project-URL: repository, https://github.com/modern-python/modern-di
|
|
6
6
|
Project-URL: docs, https://modern-di.readthedocs.io
|
|
@@ -11,11 +11,12 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.11
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.12
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
15
|
Classifier: Topic :: Software Development :: Libraries
|
|
15
16
|
Classifier: Typing :: Typed
|
|
16
17
|
Requires-Python: <4,>=3.10
|
|
17
18
|
Requires-Dist: faststream<1,>=0.5
|
|
18
|
-
Requires-Dist: modern-di>=0.
|
|
19
|
+
Requires-Dist: modern-di>=1.0.0alpha
|
|
19
20
|
Description-Content-Type: text/markdown
|
|
20
21
|
|
|
21
22
|
"Modern-DI-FastStream"
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
modern_di_faststream/__init__.py,sha256=ENQRyE_73MsxFjo608cUUb5EN1pFPC5HkS5Z3wZ5IC0,132
|
|
2
|
+
modern_di_faststream/main.py,sha256=-Sysi1rvq9mQvBNqvu3O0Lvn3EuDg2dCexOfRucRJZ4,3469
|
|
3
|
+
modern_di_faststream/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
modern_di_faststream-1.0.0.dist-info/METADATA,sha256=jNQ1aJEHuaKGmv57uTIdTsoA0LQQlp6OqnYCo0q-few,1008
|
|
5
|
+
modern_di_faststream-1.0.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
6
|
+
modern_di_faststream-1.0.0.dist-info/RECORD,,
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
modern_di_faststream/__init__.py,sha256=ENQRyE_73MsxFjo608cUUb5EN1pFPC5HkS5Z3wZ5IC0,132
|
|
2
|
-
modern_di_faststream/main.py,sha256=_c2yjgCmidf9BspUfAlatJU1PUjCgDn3BhhyASEci-k,3406
|
|
3
|
-
modern_di_faststream/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
modern_di_faststream-0.6.0.dist-info/METADATA,sha256=N6znJjks4nh9WYmd05sYPp64y37Ff7pkf5cPGp8ayhs,953
|
|
5
|
-
modern_di_faststream-0.6.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
6
|
-
modern_di_faststream-0.6.0.dist-info/RECORD,,
|