dependency-injection-pattern 0.0.4__tar.gz → 0.0.6__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.
- {dependency_injection_pattern-0.0.4/src/dependency_injection_pattern.egg-info → dependency_injection_pattern-0.0.6}/PKG-INFO +3 -3
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/pyproject.toml +2 -2
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6/src/dependency_injection_pattern.egg-info}/PKG-INFO +3 -3
- dependency_injection_pattern-0.0.6/src/dependency_injection_pattern.egg-info/requires.txt +6 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/container.py +4 -4
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/default_scope.py +1 -1
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/factories/factory.py +2 -2
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/helpers.py +1 -2
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/provider.py +1 -1
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/tests/test_container.py +1 -1
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/tests/test_examples.py +1 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/tests/test_factory.py +1 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/tests/test_provider.py +1 -0
- dependency_injection_pattern-0.0.4/src/dependency_injection_pattern.egg-info/requires.txt +0 -6
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/LICENSE +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/README.md +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/setup.cfg +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/dependency_injection_pattern.egg-info/SOURCES.txt +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/dependency_injection_pattern.egg-info/dependency_links.txt +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/dependency_injection_pattern.egg-info/top_level.txt +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/__init__.py +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/exceptions/add_exception.py +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/exceptions/container_sealed_error.py +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/exceptions/factory_provide_exception.py +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/exceptions/implementation_exception.py +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/exceptions/provide_exception.py +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/exceptions/seal_exception.py +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/factories/dependency.py +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/factories/scoped_factory.py +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/factories/singleton_factory.py +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/factories/transient_factory.py +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/factory.py +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/log.py +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/named_service.py +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/protocols/container.py +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/protocols/factory.py +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/protocols/provider.py +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/scope.py +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/service_request.py +0 -0
- {dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/exceptions.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dependency-injection-pattern
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.6
|
|
4
4
|
Summary: Python implementation of the Dependency Injection pattern.
|
|
5
5
|
Author-email: Anders Madsen <anders.madsen@alphavue.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -25,8 +25,8 @@ Classifier: Typing :: Typed
|
|
|
25
25
|
Requires-Python: >=3.10
|
|
26
26
|
Description-Content-Type: text/markdown
|
|
27
27
|
License-File: LICENSE
|
|
28
|
-
Requires-Dist: typing-utilities<0.
|
|
29
|
-
Requires-Dist: runtime-reflection-lite<0.
|
|
28
|
+
Requires-Dist: typing-utilities<0.2,>=0.1.0
|
|
29
|
+
Requires-Dist: runtime-reflection-lite<0.3,>=0.2.0
|
|
30
30
|
Provides-Extra: test
|
|
31
31
|
Requires-Dist: pytest>=8.3; extra == "test"
|
|
32
32
|
Requires-Dist: pytest-cov>=6.1; extra == "test"
|
|
@@ -28,8 +28,8 @@ classifiers = [
|
|
|
28
28
|
"Typing :: Typed"
|
|
29
29
|
]
|
|
30
30
|
dependencies = [
|
|
31
|
-
"typing-utilities >= 0.0
|
|
32
|
-
"runtime-reflection-lite >= 0.
|
|
31
|
+
"typing-utilities >= 0.1.0, < 0.2",
|
|
32
|
+
"runtime-reflection-lite >= 0.2.0, < 0.3"
|
|
33
33
|
]
|
|
34
34
|
requires-python = ">=3.10"
|
|
35
35
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dependency-injection-pattern
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.6
|
|
4
4
|
Summary: Python implementation of the Dependency Injection pattern.
|
|
5
5
|
Author-email: Anders Madsen <anders.madsen@alphavue.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -25,8 +25,8 @@ Classifier: Typing :: Typed
|
|
|
25
25
|
Requires-Python: >=3.10
|
|
26
26
|
Description-Content-Type: text/markdown
|
|
27
27
|
License-File: LICENSE
|
|
28
|
-
Requires-Dist: typing-utilities<0.
|
|
29
|
-
Requires-Dist: runtime-reflection-lite<0.
|
|
28
|
+
Requires-Dist: typing-utilities<0.2,>=0.1.0
|
|
29
|
+
Requires-Dist: runtime-reflection-lite<0.3,>=0.2.0
|
|
30
30
|
Provides-Extra: test
|
|
31
31
|
Requires-Dist: pytest>=8.3; extra == "test"
|
|
32
32
|
Requires-Dist: pytest-cov>=6.1; extra == "test"
|
{dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/container.py
RENAMED
|
@@ -195,7 +195,7 @@ class Container:
|
|
|
195
195
|
factories = { **self.__factories, **{ service: factory for service, factory in self.__named_factories.values() } }
|
|
196
196
|
for service, factory in factories.items():
|
|
197
197
|
for dep in factory.dependencies.values():
|
|
198
|
-
if
|
|
198
|
+
if dep.service not in factories:
|
|
199
199
|
if not dep.is_optional and not dep.has_default:
|
|
200
200
|
raise SealException(f"Service '{get_service_name(service)}' depends on service '{get_service_name(dep.service)}' which is not defined in container.")
|
|
201
201
|
else:
|
|
@@ -207,7 +207,7 @@ class Container:
|
|
|
207
207
|
raise SealException(f"Singleton service '{get_service_name(service)}' depends on transient service {get_service_name(dep.service)}' which is not permitted.")
|
|
208
208
|
|
|
209
209
|
return provider
|
|
210
|
-
elif provider :=self.__provider():
|
|
210
|
+
elif provider := self.__provider():
|
|
211
211
|
return provider
|
|
212
212
|
else:
|
|
213
213
|
provider = Provider(self)
|
|
@@ -215,7 +215,7 @@ class Container:
|
|
|
215
215
|
return provider
|
|
216
216
|
|
|
217
217
|
def __add_factory_pre(self, factory_type: type[Factory[T]], *args: Any) -> tuple[str, type[Any]]:
|
|
218
|
-
if self.__provider
|
|
218
|
+
if self.__provider is not None:
|
|
219
219
|
raise ContainerSealedError
|
|
220
220
|
|
|
221
221
|
if len(args) == 2:
|
|
@@ -335,7 +335,7 @@ class Container:
|
|
|
335
335
|
|
|
336
336
|
if factory:
|
|
337
337
|
return factory
|
|
338
|
-
elif default
|
|
338
|
+
elif default is not None:
|
|
339
339
|
return default
|
|
340
340
|
elif not is_optional:
|
|
341
341
|
if isinstance(service, ServiceRequest):
|
|
@@ -55,7 +55,7 @@ class DefaultScope(Scope):
|
|
|
55
55
|
self.__local.finalizer = Thread(target = finalize, args = [ current_thread(), dict ])
|
|
56
56
|
self.__local.finalizer.start()
|
|
57
57
|
|
|
58
|
-
if not
|
|
58
|
+
if service not in self.__local.dict:
|
|
59
59
|
impl = factory()
|
|
60
60
|
if current_thread() != main_thread() and is_context(service):
|
|
61
61
|
# finalizer is only implemented when thread is not main thread, otherwise object would never be exited (eg. finalized)
|
|
@@ -30,7 +30,7 @@ class Factory(Generic[T]):
|
|
|
30
30
|
sig = get_constructor(service)
|
|
31
31
|
elif isinstance(implementation, type):
|
|
32
32
|
sig = get_constructor(cast(type, implementation))
|
|
33
|
-
if
|
|
33
|
+
if service is not NamedService and not issubclass_typing(implementation, service):
|
|
34
34
|
raise ImplementationException(service, implementation, "Implementation class is not derived from service")
|
|
35
35
|
elif implementation is service:
|
|
36
36
|
raise ImplementationException(service, implementation, "Implementation equals service")
|
|
@@ -54,7 +54,7 @@ class Factory(Generic[T]):
|
|
|
54
54
|
else:
|
|
55
55
|
raise ImplementationException(service, implementation, "Implementation does not resolve into a class derived from service")
|
|
56
56
|
|
|
57
|
-
if sig
|
|
57
|
+
if sig is not None:
|
|
58
58
|
parameters = [ p for p in sig.parameters if p.kind == ParameterKind.POSITIONAL_OR_KEYWORD ]
|
|
59
59
|
missing_annotations = [ p.name for p in parameters if not p.parameter_type ]
|
|
60
60
|
self.__dependencies = { p.name: Dependency(p.name, p.parameter_type, p.default) for p in parameters }
|
{dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/helpers.py
RENAMED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
from typing import MutableMapping, Protocol, TypeVar, cast, runtime_checkable
|
|
2
|
-
from di.core.factory import Factory
|
|
3
2
|
from types import TracebackType
|
|
4
3
|
from typingutils import AnyType, issubclass_typing, get_type_name
|
|
5
4
|
|
|
@@ -35,7 +34,7 @@ def get_provided_service_from_annotation(annotation: AnyType) -> tuple[AnyType,
|
|
|
35
34
|
__CONTEXT_SERVICES__: MutableMapping[type, bool] = {}
|
|
36
35
|
|
|
37
36
|
def is_context(cls: type) -> bool:
|
|
38
|
-
if not
|
|
37
|
+
if cls not in __CONTEXT_SERVICES__:
|
|
39
38
|
# reflection = reflect_class(cls)
|
|
40
39
|
|
|
41
40
|
# if "__enter__" in reflection.functions and "__exit__" in reflection.functions:
|
{dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/provider.py
RENAMED
|
@@ -68,7 +68,7 @@ class Provider:
|
|
|
68
68
|
else:
|
|
69
69
|
result = self.__container._get(cast(type[T], service)) # pyright: ignore[reportPrivateUsage]
|
|
70
70
|
|
|
71
|
-
if result
|
|
71
|
+
if result is None:
|
|
72
72
|
# optional requirements may return None
|
|
73
73
|
if is_optional:
|
|
74
74
|
return None # pyright: ignore[reportReturnType]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/factory.py
RENAMED
|
File without changes
|
{dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/log.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/core/scope.py
RENAMED
|
File without changes
|
|
File without changes
|
{dependency_injection_pattern-0.0.4 → dependency_injection_pattern-0.0.6}/src/di/exceptions.py
RENAMED
|
File without changes
|