modern-di 0.1.0__py3-none-any.whl → 0.2.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.
Potentially problematic release.
This version of modern-di might be problematic. Click here for more details.
- modern_di/resolvers/__init__.py +2 -0
- modern_di/resolvers/factory.py +2 -12
- modern_di/resolvers/resource.py +4 -5
- modern_di/resolvers/singleton.py +56 -0
- {modern_di-0.1.0.dist-info → modern_di-0.2.0.dist-info}/METADATA +5 -5
- modern_di-0.2.0.dist-info/RECORD +15 -0
- modern_di-0.1.0.dist-info/RECORD +0 -14
- {modern_di-0.1.0.dist-info → modern_di-0.2.0.dist-info}/WHEEL +0 -0
- {modern_di-0.1.0.dist-info → modern_di-0.2.0.dist-info}/licenses/LICENSE +0 -0
modern_di/resolvers/__init__.py
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
from modern_di.resolvers.base import AbstractResolver, BaseCreatorResolver
|
|
2
2
|
from modern_di.resolvers.factory import Factory
|
|
3
3
|
from modern_di.resolvers.resource import Resource
|
|
4
|
+
from modern_di.resolvers.singleton import Singleton
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
__all__ = [
|
|
7
8
|
"AbstractResolver",
|
|
8
9
|
"BaseCreatorResolver",
|
|
9
10
|
"Factory",
|
|
11
|
+
"Singleton",
|
|
10
12
|
"Resource",
|
|
11
13
|
]
|
modern_di/resolvers/factory.py
CHANGED
|
@@ -26,21 +26,11 @@ class Factory(BaseCreatorResolver[T_co]):
|
|
|
26
26
|
if (override := container.fetch_override(self.resolver_id)) is not None:
|
|
27
27
|
return typing.cast(T_co, override)
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
if resolver_state.instance is not None:
|
|
31
|
-
return typing.cast(T_co, resolver_state.instance)
|
|
32
|
-
|
|
33
|
-
resolver_state.instance = typing.cast(T_co, await self._async_build_creator(container))
|
|
34
|
-
return resolver_state.instance
|
|
29
|
+
return typing.cast(T_co, await self._async_build_creator(container))
|
|
35
30
|
|
|
36
31
|
def sync_resolve(self, container: Container) -> T_co:
|
|
37
32
|
container = container.find_container(self.scope)
|
|
38
33
|
if (override := container.fetch_override(self.resolver_id)) is not None:
|
|
39
34
|
return typing.cast(T_co, override)
|
|
40
35
|
|
|
41
|
-
|
|
42
|
-
if resolver_state.instance is not None:
|
|
43
|
-
return typing.cast(T_co, resolver_state.instance)
|
|
44
|
-
|
|
45
|
-
resolver_state.instance = self._sync_build_creator(container)
|
|
46
|
-
return typing.cast(T_co, resolver_state.instance)
|
|
36
|
+
return typing.cast(T_co, self._sync_build_creator(container))
|
modern_di/resolvers/resource.py
CHANGED
|
@@ -46,13 +46,13 @@ class Resource(BaseCreatorResolver[T_co]):
|
|
|
46
46
|
return typing.cast(T_co, override)
|
|
47
47
|
|
|
48
48
|
resolver_state = container.fetch_resolver_state(
|
|
49
|
-
self.resolver_id, is_async_resource=self._is_async, is_lock_required=
|
|
49
|
+
self.resolver_id, is_async_resource=self._is_async, is_lock_required=True
|
|
50
50
|
)
|
|
51
51
|
if resolver_state.instance is not None:
|
|
52
52
|
return typing.cast(T_co, resolver_state.instance)
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
assert resolver_state.resolver_lock
|
|
55
|
+
await resolver_state.resolver_lock.acquire()
|
|
56
56
|
|
|
57
57
|
try:
|
|
58
58
|
if resolver_state.instance is not None:
|
|
@@ -67,8 +67,7 @@ class Resource(BaseCreatorResolver[T_co]):
|
|
|
67
67
|
resolver_state.context_stack = contextlib.ExitStack()
|
|
68
68
|
resolver_state.instance = resolver_state.context_stack.enter_context(_intermediate_)
|
|
69
69
|
finally:
|
|
70
|
-
|
|
71
|
-
resolver_state.resolver_lock.release()
|
|
70
|
+
resolver_state.resolver_lock.release()
|
|
72
71
|
|
|
73
72
|
return typing.cast(T_co, resolver_state.instance)
|
|
74
73
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import enum
|
|
2
|
+
import typing
|
|
3
|
+
|
|
4
|
+
from modern_di import Container
|
|
5
|
+
from modern_di.resolvers import BaseCreatorResolver
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
T_co = typing.TypeVar("T_co", covariant=True)
|
|
9
|
+
P = typing.ParamSpec("P")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Singleton(BaseCreatorResolver[T_co]):
|
|
13
|
+
__slots__ = [*BaseCreatorResolver.BASE_SLOTS, "_creator"]
|
|
14
|
+
|
|
15
|
+
def __init__(
|
|
16
|
+
self,
|
|
17
|
+
scope: enum.IntEnum,
|
|
18
|
+
creator: typing.Callable[P, T_co],
|
|
19
|
+
*args: P.args,
|
|
20
|
+
**kwargs: P.kwargs,
|
|
21
|
+
) -> None:
|
|
22
|
+
super().__init__(scope, creator, *args, **kwargs)
|
|
23
|
+
|
|
24
|
+
async def async_resolve(self, container: Container) -> T_co:
|
|
25
|
+
container = container.find_container(self.scope)
|
|
26
|
+
if (override := container.fetch_override(self.resolver_id)) is not None:
|
|
27
|
+
return typing.cast(T_co, override)
|
|
28
|
+
|
|
29
|
+
resolver_state = container.fetch_resolver_state(self.resolver_id, is_lock_required=True)
|
|
30
|
+
if resolver_state.instance is not None:
|
|
31
|
+
return typing.cast(T_co, resolver_state.instance)
|
|
32
|
+
|
|
33
|
+
assert resolver_state.resolver_lock
|
|
34
|
+
await resolver_state.resolver_lock.acquire()
|
|
35
|
+
|
|
36
|
+
try:
|
|
37
|
+
if resolver_state.instance is not None:
|
|
38
|
+
return typing.cast(T_co, resolver_state.instance)
|
|
39
|
+
|
|
40
|
+
resolver_state.instance = typing.cast(T_co, await self._async_build_creator(container))
|
|
41
|
+
finally:
|
|
42
|
+
resolver_state.resolver_lock.release()
|
|
43
|
+
|
|
44
|
+
return resolver_state.instance
|
|
45
|
+
|
|
46
|
+
def sync_resolve(self, container: Container) -> T_co:
|
|
47
|
+
container = container.find_container(self.scope)
|
|
48
|
+
if (override := container.fetch_override(self.resolver_id)) is not None:
|
|
49
|
+
return typing.cast(T_co, override)
|
|
50
|
+
|
|
51
|
+
resolver_state = container.fetch_resolver_state(self.resolver_id)
|
|
52
|
+
if resolver_state.instance is not None:
|
|
53
|
+
return typing.cast(T_co, resolver_state.instance)
|
|
54
|
+
|
|
55
|
+
resolver_state.instance = self._sync_build_creator(container)
|
|
56
|
+
return typing.cast(T_co, resolver_state.instance)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: modern-di
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary:
|
|
5
|
-
Project-URL: repository, https://github.com/modern-python/
|
|
6
|
-
Project-URL: docs, https://
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Dependency Injection framework with IOC-container and scopes
|
|
5
|
+
Project-URL: repository, https://github.com/modern-python/modern-di
|
|
6
|
+
Project-URL: docs, https://modern-di.readthedocs.io
|
|
7
7
|
Author-email: Artur Shiriev <me@shiriev.ru>
|
|
8
8
|
License-Expression: MIT
|
|
9
9
|
License-File: LICENSE
|
|
@@ -28,7 +28,7 @@ Description-Content-Type: text/markdown
|
|
|
28
28
|
Dependency injection framework for Python inspired by `dependency-injector` and `dishka`.
|
|
29
29
|
|
|
30
30
|
It is production-ready and gives you the following:
|
|
31
|
-
-
|
|
31
|
+
- DI framework with IOC-container and scopes.
|
|
32
32
|
- Async and sync resolving.
|
|
33
33
|
- Python 3.10-3.13 support.
|
|
34
34
|
- Full coverage by types annotations (mypy in strict mode).
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
modern_di/__init__.py,sha256=2xhgfqi4gpzPrlfam5HSwTFRroWmYIybDgsSYD9pPNg,194
|
|
2
|
+
modern_di/container.py,sha256=o-6_eoSGpOrIZlAXDryISWmgnSLq7u0YAVRXHvkWU0s,3742
|
|
3
|
+
modern_di/graph.py,sha256=V6LUbtcZb64jBD-GJB2bJijEcPBHSYEEI9WZGflrFpQ,1335
|
|
4
|
+
modern_di/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
modern_di/resolver_state.py,sha256=rRIoyWPK7XtMeWPBFuEe8t81WdrHbj5-jtpOqZWf0jY,1206
|
|
6
|
+
modern_di/scope.py,sha256=nnrTLnFT_dMDLVIwvJHcGlJsB2k1WIHusrRSGQIMEsg,97
|
|
7
|
+
modern_di/resolvers/__init__.py,sha256=560FLaWh7hjqp5ghOHsEDWl8wmoPGXZ-UUO9GgYusgc,340
|
|
8
|
+
modern_di/resolvers/base.py,sha256=BMZbYfkIzAW8-8CQ9aRVIu5D8zw9owKv4nz-z0EMYmg,2897
|
|
9
|
+
modern_di/resolvers/factory.py,sha256=tMOxpXp-zaXiSsDGUp68L2mtcfF7K02ZdF-LglH4phs,1164
|
|
10
|
+
modern_di/resolvers/resource.py,sha256=8qtyIxspbtW7Q3Yo1Y6risNamG0H3XZNU0G9t-lfZjk,3628
|
|
11
|
+
modern_di/resolvers/singleton.py,sha256=k70nEaeBqsu-uHQFqsn8XZh-aw2tQR-J5ImLED6GQGg,1978
|
|
12
|
+
modern_di-0.2.0.dist-info/METADATA,sha256=uLMl5mJ78gixE_23iXUhMXKo2hZQao-Oc3zPkv2AtOY,1846
|
|
13
|
+
modern_di-0.2.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
14
|
+
modern_di-0.2.0.dist-info/licenses/LICENSE,sha256=aA5_eJwDKqnGvL7PbkPb9x5f-VGIqZ9cvWWkeGqeD90,1070
|
|
15
|
+
modern_di-0.2.0.dist-info/RECORD,,
|
modern_di-0.1.0.dist-info/RECORD
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
modern_di/__init__.py,sha256=2xhgfqi4gpzPrlfam5HSwTFRroWmYIybDgsSYD9pPNg,194
|
|
2
|
-
modern_di/container.py,sha256=o-6_eoSGpOrIZlAXDryISWmgnSLq7u0YAVRXHvkWU0s,3742
|
|
3
|
-
modern_di/graph.py,sha256=V6LUbtcZb64jBD-GJB2bJijEcPBHSYEEI9WZGflrFpQ,1335
|
|
4
|
-
modern_di/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
modern_di/resolver_state.py,sha256=rRIoyWPK7XtMeWPBFuEe8t81WdrHbj5-jtpOqZWf0jY,1206
|
|
6
|
-
modern_di/scope.py,sha256=nnrTLnFT_dMDLVIwvJHcGlJsB2k1WIHusrRSGQIMEsg,97
|
|
7
|
-
modern_di/resolvers/__init__.py,sha256=ubCeXD-44otfS1-AG5vRbTaqn8d6szY7cKQTprFT3Pk,271
|
|
8
|
-
modern_di/resolvers/base.py,sha256=BMZbYfkIzAW8-8CQ9aRVIu5D8zw9owKv4nz-z0EMYmg,2897
|
|
9
|
-
modern_di/resolvers/factory.py,sha256=CyMvl--t3bCapxARFnCKNJNgy1svCR5c9HcwHm85G8Q,1650
|
|
10
|
-
modern_di/resolvers/resource.py,sha256=s0c2PQQSjffdKKXxZ6fJVKJaiqqBgQLZ8mTpzKjDb4Q,3688
|
|
11
|
-
modern_di-0.1.0.dist-info/METADATA,sha256=t_wifprG9bqMg-H6l8kTRoWYFPZcbJm6bMtBjsaJLeM,1825
|
|
12
|
-
modern_di-0.1.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
13
|
-
modern_di-0.1.0.dist-info/licenses/LICENSE,sha256=aA5_eJwDKqnGvL7PbkPb9x5f-VGIqZ9cvWWkeGqeD90,1070
|
|
14
|
-
modern_di-0.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|