modern-di 0.10.0__tar.gz → 0.11.0__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.

Potentially problematic release.


This version of modern-di might be problematic. Click here for more details.

Files changed (21) hide show
  1. {modern_di-0.10.0 → modern_di-0.11.0}/PKG-INFO +22 -4
  2. {modern_di-0.10.0 → modern_di-0.11.0}/modern_di/providers/__init__.py +2 -0
  3. modern_di-0.11.0/modern_di/providers/object.py +27 -0
  4. {modern_di-0.10.0 → modern_di-0.11.0}/modern_di/providers/resource.py +1 -1
  5. {modern_di-0.10.0 → modern_di-0.11.0}/.gitignore +0 -0
  6. {modern_di-0.10.0 → modern_di-0.11.0}/modern_di/__init__.py +0 -0
  7. {modern_di-0.10.0 → modern_di-0.11.0}/modern_di/container.py +0 -0
  8. {modern_di-0.10.0 → modern_di-0.11.0}/modern_di/graph.py +0 -0
  9. {modern_di-0.10.0 → modern_di-0.11.0}/modern_di/provider_state.py +0 -0
  10. {modern_di-0.10.0 → modern_di-0.11.0}/modern_di/providers/abstract.py +0 -0
  11. {modern_di-0.10.0 → modern_di-0.11.0}/modern_di/providers/container_provider.py +0 -0
  12. {modern_di-0.10.0 → modern_di-0.11.0}/modern_di/providers/context_adapter.py +0 -0
  13. {modern_di-0.10.0 → modern_di-0.11.0}/modern_di/providers/dict.py +0 -0
  14. {modern_di-0.10.0 → modern_di-0.11.0}/modern_di/providers/factory.py +0 -0
  15. {modern_di-0.10.0 → modern_di-0.11.0}/modern_di/providers/injected_factory.py +0 -0
  16. {modern_di-0.10.0 → modern_di-0.11.0}/modern_di/providers/list.py +0 -0
  17. {modern_di-0.10.0 → modern_di-0.11.0}/modern_di/providers/selector.py +0 -0
  18. {modern_di-0.10.0 → modern_di-0.11.0}/modern_di/providers/singleton.py +0 -0
  19. {modern_di-0.10.0 → modern_di-0.11.0}/modern_di/py.typed +0 -0
  20. {modern_di-0.10.0 → modern_di-0.11.0}/modern_di/scope.py +0 -0
  21. {modern_di-0.10.0 → modern_di-0.11.0}/pyproject.toml +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: modern-di
3
- Version: 0.10.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
- ## Describe resources and classes:
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 (IoC-container)
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
- ## Create container and resolve dependencies in your code
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,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
@@ -1,4 +1,4 @@
1
- import contextlib
1
+ import contextlib # noqa: A005
2
2
  import enum
3
3
  import inspect
4
4
  import typing
File without changes
File without changes