modern-di 0.10.0__py3-none-any.whl → 0.11.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/providers/__init__.py +2 -0
- modern_di/providers/object.py +27 -0
- modern_di/providers/resource.py +1 -1
- {modern_di-0.10.0.dist-info → modern_di-0.11.0.dist-info}/METADATA +22 -4
- {modern_di-0.10.0.dist-info → modern_di-0.11.0.dist-info}/RECORD +6 -5
- {modern_di-0.10.0.dist-info → modern_di-0.11.0.dist-info}/WHEEL +0 -0
modern_di/providers/__init__.py
CHANGED
|
@@ -4,6 +4,7 @@ from modern_di.providers.context_adapter import ContextAdapter
|
|
|
4
4
|
from modern_di.providers.dict import Dict
|
|
5
5
|
from modern_di.providers.factory import Factory
|
|
6
6
|
from modern_di.providers.list import List
|
|
7
|
+
from modern_di.providers.object import Object
|
|
7
8
|
from modern_di.providers.resource import Resource
|
|
8
9
|
from modern_di.providers.selector import Selector
|
|
9
10
|
from modern_di.providers.singleton import Singleton
|
|
@@ -16,6 +17,7 @@ __all__ = [
|
|
|
16
17
|
"Dict",
|
|
17
18
|
"Factory",
|
|
18
19
|
"List",
|
|
20
|
+
"Object",
|
|
19
21
|
"Resource",
|
|
20
22
|
"Selector",
|
|
21
23
|
"Singleton",
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import enum
|
|
2
|
+
import typing
|
|
3
|
+
|
|
4
|
+
from modern_di import Container
|
|
5
|
+
from modern_di.providers.abstract import AbstractOverrideProvider
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
T_co = typing.TypeVar("T_co", covariant=True)
|
|
9
|
+
P = typing.ParamSpec("P")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Object(AbstractOverrideProvider[T_co]):
|
|
13
|
+
__slots__ = [*AbstractOverrideProvider.BASE_SLOTS, "_obj"]
|
|
14
|
+
|
|
15
|
+
def __init__(self, scope: enum.IntEnum, obj: T_co) -> None:
|
|
16
|
+
super().__init__(scope)
|
|
17
|
+
self._obj: typing.Final = obj
|
|
18
|
+
|
|
19
|
+
async def async_resolve(self, container: Container) -> T_co:
|
|
20
|
+
return self.sync_resolve(container)
|
|
21
|
+
|
|
22
|
+
def sync_resolve(self, container: Container) -> T_co:
|
|
23
|
+
container = container.find_container(self.scope)
|
|
24
|
+
if (override := container.fetch_override(self.provider_id)) is not None:
|
|
25
|
+
return typing.cast(T_co, override)
|
|
26
|
+
|
|
27
|
+
return self._obj
|
modern_di/providers/resource.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: modern-di
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11.0
|
|
4
4
|
Summary: Dependency Injection framework with IOC-container and scopes
|
|
5
5
|
Project-URL: repository, https://github.com/modern-python/modern-di
|
|
6
6
|
Project-URL: docs, https://modern-di.readthedocs.io
|
|
@@ -40,7 +40,17 @@ It is in development state yet and gives you the following:
|
|
|
40
40
|
|
|
41
41
|
📚 [Documentation](https://modern-di.readthedocs.io)
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
# Quickstart
|
|
44
|
+
|
|
45
|
+
## 1. Install `modern-di` using your favorite tool:
|
|
46
|
+
|
|
47
|
+
```shell
|
|
48
|
+
pip install modern-di
|
|
49
|
+
uv add modern-di
|
|
50
|
+
poetry add modern-di
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## 2. Describe resources and classes:
|
|
44
54
|
```python
|
|
45
55
|
import dataclasses
|
|
46
56
|
import logging
|
|
@@ -74,7 +84,7 @@ class DependentFactory:
|
|
|
74
84
|
async_resource: str
|
|
75
85
|
```
|
|
76
86
|
|
|
77
|
-
## Describe dependencies graph
|
|
87
|
+
## 3. Describe dependencies graph
|
|
78
88
|
```python
|
|
79
89
|
from modern_di import BaseGraph, Scope, providers
|
|
80
90
|
|
|
@@ -91,7 +101,15 @@ class Dependencies(BaseGraph):
|
|
|
91
101
|
)
|
|
92
102
|
```
|
|
93
103
|
|
|
94
|
-
##
|
|
104
|
+
## 4.1. Integrate with your framework
|
|
105
|
+
|
|
106
|
+
For now there are integration for the following frameworks:
|
|
107
|
+
1. [FastAPI](https://modern-di.readthedocs.io/en/latest/integrations/fastapi.html)
|
|
108
|
+
2. [LiteStar](https://modern-di.readthedocs.io/en/latest/integrations/litestar.html)
|
|
109
|
+
|
|
110
|
+
## 4.2. Or use `modern-di` without integrations
|
|
111
|
+
|
|
112
|
+
Create container and resolve dependencies in your code
|
|
95
113
|
```python
|
|
96
114
|
from modern_di import Container, Scope
|
|
97
115
|
|
|
@@ -4,7 +4,7 @@ modern_di/graph.py,sha256=X60wtG3Mqus_5YZNiZlQuXoHODBp7rYl_IHJs7GzSQM,1356
|
|
|
4
4
|
modern_di/provider_state.py,sha256=oU08QnMr0yhIZKkz0Pee8_RnWtETDE9ux4JB83qhwTI,1358
|
|
5
5
|
modern_di/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
6
|
modern_di/scope.py,sha256=e6Olc-CF89clbYDNGciy-F8EqJt1Mw2703zfuJaEY94,113
|
|
7
|
-
modern_di/providers/__init__.py,sha256=
|
|
7
|
+
modern_di/providers/__init__.py,sha256=x4dzOpyyY6puc_ogtjch4xAdzz-8fN_dWefTjS1k2aI,709
|
|
8
8
|
modern_di/providers/abstract.py,sha256=dgtAwzwtK-zyIHroxAT3QB5CV06sx3PUugYweZexkMc,3408
|
|
9
9
|
modern_di/providers/container_provider.py,sha256=r5IEQXgKtPwvHvbqkbPnmGyDGGCCjokTtdard9Rvt40,548
|
|
10
10
|
modern_di/providers/context_adapter.py,sha256=_b1x3ToQPWT-9KkDioFhw1W8Q1VXZYUnczfYzMTobVA,760
|
|
@@ -12,9 +12,10 @@ modern_di/providers/dict.py,sha256=nCU9iaqteYHDbILAfhrdnbMgS9_emE4MS7Xn2VoUlPo,8
|
|
|
12
12
|
modern_di/providers/factory.py,sha256=Nn9WZuOHF4r5Go4vOuW_jAjmXs0A2WJCGiGQ1eUFB58,1507
|
|
13
13
|
modern_di/providers/injected_factory.py,sha256=KkDww-zUgm41LFt5j8crRzzFuBSkmKvOfptzHWMgVok,1848
|
|
14
14
|
modern_di/providers/list.py,sha256=3hx34RfBRmqzh-cT5D6wSTDJPkBGMK_ul4n9gQz-o9M,769
|
|
15
|
-
modern_di/providers/
|
|
15
|
+
modern_di/providers/object.py,sha256=Sm0mb3Ua7cZ5Ay65fLvl7fnJDSQrQZwvzio3lkkXP2A,825
|
|
16
|
+
modern_di/providers/resource.py,sha256=Vp8psY_svOQEJ_38DWhR8ASYpqhP9DoB7bC0jH0IlaU,4605
|
|
16
17
|
modern_di/providers/selector.py,sha256=RQbHD2-Liw-TGqu6UELbfCzXYuqxiO_Mg1tLyF3mKQo,1419
|
|
17
18
|
modern_di/providers/singleton.py,sha256=_hUpCmbHgLAigdhBiu0zypwWwrIGdB6_oZkGfuLxzNE,2372
|
|
18
|
-
modern_di-0.
|
|
19
|
-
modern_di-0.
|
|
20
|
-
modern_di-0.
|
|
19
|
+
modern_di-0.11.0.dist-info/METADATA,sha256=kal_732xHN0mXUyxkNdv4gDCK_MlQM12xOHiHcClcJs,5950
|
|
20
|
+
modern_di-0.11.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
21
|
+
modern_di-0.11.0.dist-info/RECORD,,
|
|
File without changes
|