modern-di-faststream 2.0.0a0__tar.gz → 2.0.0a2__tar.gz
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-2.0.0a0 → modern_di_faststream-2.0.0a2}/PKG-INFO +2 -2
- {modern_di_faststream-2.0.0a0 → modern_di_faststream-2.0.0a2}/modern_di_faststream/main.py +14 -6
- {modern_di_faststream-2.0.0a0 → modern_di_faststream-2.0.0a2}/pyproject.toml +2 -2
- {modern_di_faststream-2.0.0a0 → modern_di_faststream-2.0.0a2}/.gitignore +0 -0
- {modern_di_faststream-2.0.0a0 → modern_di_faststream-2.0.0a2}/README.md +0 -0
- {modern_di_faststream-2.0.0a0 → modern_di_faststream-2.0.0a2}/modern_di_faststream/__init__.py +0 -0
- {modern_di_faststream-2.0.0a0 → modern_di_faststream-2.0.0a2}/modern_di_faststream/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: modern-di-faststream
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.0a2
|
|
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
|
|
@@ -16,7 +16,7 @@ Classifier: Topic :: Software Development :: Libraries
|
|
|
16
16
|
Classifier: Typing :: Typed
|
|
17
17
|
Requires-Python: <4,>=3.10
|
|
18
18
|
Requires-Dist: faststream<1,>=0.5
|
|
19
|
-
Requires-Dist: modern-di>=
|
|
19
|
+
Requires-Dist: modern-di>=2.0.0alpha1
|
|
20
20
|
Description-Content-Type: text/markdown
|
|
21
21
|
|
|
22
22
|
"Modern-DI-FastStream"
|
|
@@ -7,12 +7,16 @@ 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 Container, providers
|
|
10
|
+
from modern_di import Container, Scope, providers
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
T_co = typing.TypeVar("T_co", covariant=True)
|
|
14
14
|
P = typing.ParamSpec("P")
|
|
15
15
|
|
|
16
|
+
|
|
17
|
+
faststream_message = providers.ContextProvider(scope=Scope.REQUEST, context_type=faststream.StreamMessage)
|
|
18
|
+
|
|
19
|
+
|
|
16
20
|
_major, _minor, *_ = version("faststream").split(".")
|
|
17
21
|
_OLD_MIDDLEWARES = int(_major) == 0 and int(_minor) < 6 # noqa: PLR2004
|
|
18
22
|
|
|
@@ -40,11 +44,14 @@ class _DiMiddleware(faststream.BaseMiddleware, typing.Generic[P]):
|
|
|
40
44
|
request_container = self.di_container.build_child_container(
|
|
41
45
|
scope=modern_di.Scope.REQUEST, context={faststream.StreamMessage: msg}
|
|
42
46
|
)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
typing.
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
try:
|
|
48
|
+
with self.faststream_context.scope("request_container", request_container):
|
|
49
|
+
return typing.cast(
|
|
50
|
+
typing.AsyncIterator[DecodedMessage],
|
|
51
|
+
await call_next(msg),
|
|
52
|
+
)
|
|
53
|
+
finally:
|
|
54
|
+
await request_container.close_async()
|
|
48
55
|
|
|
49
56
|
if _OLD_MIDDLEWARES: # pragma: no cover
|
|
50
57
|
|
|
@@ -71,6 +78,7 @@ def setup_di(
|
|
|
71
78
|
msg = "Broker must be defined to setup DI"
|
|
72
79
|
raise RuntimeError(msg)
|
|
73
80
|
|
|
81
|
+
container.providers_registry.add_providers(faststream_message=faststream_message)
|
|
74
82
|
app.context.set_global("di_container", container)
|
|
75
83
|
app.broker.add_middleware(_DIMiddlewareFactory(container))
|
|
76
84
|
return container
|
|
@@ -15,8 +15,8 @@ classifiers = [
|
|
|
15
15
|
"Typing :: Typed",
|
|
16
16
|
"Topic :: Software Development :: Libraries",
|
|
17
17
|
]
|
|
18
|
-
dependencies = ["faststream>=0.5,<1", "modern-di>=
|
|
19
|
-
version = "2.0.
|
|
18
|
+
dependencies = ["faststream>=0.5,<1", "modern-di>=2.0.0alpha1"]
|
|
19
|
+
version = "2.0.0a2"
|
|
20
20
|
|
|
21
21
|
[project.urls]
|
|
22
22
|
repository = "https://github.com/modern-python/modern-di"
|
|
File without changes
|
|
File without changes
|
{modern_di_faststream-2.0.0a0 → modern_di_faststream-2.0.0a2}/modern_di_faststream/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|