modern-di-faststream 0.6.0__tar.gz → 1.0.0a0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: modern-di-faststream
3
- Version: 0.6.0
3
+ Version: 1.0.0a0
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
@@ -15,7 +15,7 @@ Classifier: Topic :: Software Development :: Libraries
15
15
  Classifier: Typing :: Typed
16
16
  Requires-Python: <4,>=3.10
17
17
  Requires-Dist: faststream<1,>=0.5
18
- Requires-Dist: modern-di>=0.13.0
18
+ Requires-Dist: modern-di>=1
19
19
  Description-Content-Type: text/markdown
20
20
 
21
21
  "Modern-DI-FastStream"
@@ -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, Scope, providers
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
- scope: Scope = Scope.APP,
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
- return await request_container.resolve_provider(self.dependency)
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(dependency: providers.AbstractProvider[T_co], *, use_cache: bool = True, cast: bool = False) -> T_co: # noqa: N802
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))
@@ -14,8 +14,8 @@ classifiers = [
14
14
  "Typing :: Typed",
15
15
  "Topic :: Software Development :: Libraries",
16
16
  ]
17
- dependencies = ["faststream>=0.5,<1", "modern-di>=0.13.0"]
18
- version = "0.6.0"
17
+ dependencies = ["faststream>=0.5,<1", "modern-di>=1"]
18
+ version = "1.0.0a0"
19
19
 
20
20
  [project.urls]
21
21
  repository = "https://github.com/modern-python/modern-di"