dependency-injection-pattern 0.0.2__tar.gz → 0.0.4__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.
Files changed (40) hide show
  1. {dependency_injection_pattern-0.0.2/src/dependency_injection_pattern.egg-info → dependency_injection_pattern-0.0.4}/PKG-INFO +3 -3
  2. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/pyproject.toml +3 -2
  3. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4/src/dependency_injection_pattern.egg-info}/PKG-INFO +3 -3
  4. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/dependency_injection_pattern.egg-info/requires.txt +1 -1
  5. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/core/container.py +16 -16
  6. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/core/default_scope.py +0 -1
  7. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/core/factories/factory.py +3 -3
  8. dependency_injection_pattern-0.0.4/src/di/core/scope.py +24 -0
  9. dependency_injection_pattern-0.0.2/src/di/core/scope.py +0 -15
  10. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/LICENSE +0 -0
  11. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/README.md +0 -0
  12. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/setup.cfg +0 -0
  13. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/dependency_injection_pattern.egg-info/SOURCES.txt +0 -0
  14. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/dependency_injection_pattern.egg-info/dependency_links.txt +0 -0
  15. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/dependency_injection_pattern.egg-info/top_level.txt +0 -0
  16. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/__init__.py +0 -0
  17. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/core/exceptions/add_exception.py +0 -0
  18. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/core/exceptions/container_sealed_error.py +0 -0
  19. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/core/exceptions/factory_provide_exception.py +0 -0
  20. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/core/exceptions/implementation_exception.py +0 -0
  21. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/core/exceptions/provide_exception.py +0 -0
  22. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/core/exceptions/seal_exception.py +0 -0
  23. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/core/factories/dependency.py +0 -0
  24. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/core/factories/scoped_factory.py +0 -0
  25. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/core/factories/singleton_factory.py +0 -0
  26. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/core/factories/transient_factory.py +0 -0
  27. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/core/factory.py +0 -0
  28. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/core/helpers.py +0 -0
  29. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/core/log.py +0 -0
  30. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/core/named_service.py +0 -0
  31. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/core/protocols/container.py +0 -0
  32. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/core/protocols/factory.py +0 -0
  33. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/core/protocols/provider.py +0 -0
  34. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/core/provider.py +0 -0
  35. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/core/service_request.py +0 -0
  36. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/src/di/exceptions.py +0 -0
  37. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/tests/test_container.py +0 -0
  38. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/tests/test_examples.py +0 -0
  39. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/tests/test_factory.py +0 -0
  40. {dependency_injection_pattern-0.0.2 → dependency_injection_pattern-0.0.4}/tests/test_provider.py +0 -0
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dependency-injection-pattern
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: Python implementation of the Dependency Injection pattern.
5
5
  Author-email: Anders Madsen <anders.madsen@alphavue.com>
6
- License: MIT
6
+ License-Expression: MIT
7
7
  Project-URL: repository, https://github.com/apmadsen/dependency-injection-pattern
8
8
  Keywords: windows,linux,dependency injection,di,dependency,injection,IoC
9
9
  Classifier: Development Status :: 5 - Production/Stable
@@ -26,7 +26,7 @@ Requires-Python: >=3.10
26
26
  Description-Content-Type: text/markdown
27
27
  License-File: LICENSE
28
28
  Requires-Dist: typing-utilities<0.1,>=0.0.3
29
- Requires-Dist: runtime-reflection-lite<0.1,>=0.0.0
29
+ Requires-Dist: runtime-reflection-lite<0.2,>=0.1.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"
@@ -7,7 +7,8 @@ readme = "README.md"
7
7
  authors = [
8
8
  { name = "Anders Madsen", email = "anders.madsen@alphavue.com" }
9
9
  ]
10
- license = { text = "MIT" }
10
+ license = "MIT"
11
+ license-files = [ "LICENSE"]
11
12
  classifiers = [
12
13
  "Development Status :: 5 - Production/Stable",
13
14
  "Development Status :: 6 - Mature",
@@ -28,7 +29,7 @@ classifiers = [
28
29
  ]
29
30
  dependencies = [
30
31
  "typing-utilities >= 0.0.3, < 0.1",
31
- "runtime-reflection-lite >= 0.0.0, < 0.1"
32
+ "runtime-reflection-lite >= 0.1.0, < 0.2"
32
33
  ]
33
34
  requires-python = ">=3.10"
34
35
 
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dependency-injection-pattern
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: Python implementation of the Dependency Injection pattern.
5
5
  Author-email: Anders Madsen <anders.madsen@alphavue.com>
6
- License: MIT
6
+ License-Expression: MIT
7
7
  Project-URL: repository, https://github.com/apmadsen/dependency-injection-pattern
8
8
  Keywords: windows,linux,dependency injection,di,dependency,injection,IoC
9
9
  Classifier: Development Status :: 5 - Production/Stable
@@ -26,7 +26,7 @@ Requires-Python: >=3.10
26
26
  Description-Content-Type: text/markdown
27
27
  License-File: LICENSE
28
28
  Requires-Dist: typing-utilities<0.1,>=0.0.3
29
- Requires-Dist: runtime-reflection-lite<0.1,>=0.0.0
29
+ Requires-Dist: runtime-reflection-lite<0.2,>=0.1.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"
@@ -1,5 +1,5 @@
1
1
  typing-utilities<0.1,>=0.0.3
2
- runtime-reflection-lite<0.1,>=0.0.0
2
+ runtime-reflection-lite<0.2,>=0.1.0
3
3
 
4
4
  [test]
5
5
  pytest>=8.3
@@ -1,9 +1,9 @@
1
1
  from __future__ import annotations
2
2
  from typing import TypeVar, Callable, Any, cast, overload, TYPE_CHECKING
3
- from typingutils import is_type, isinstance_typing, get_optional_type, AnyFunction
3
+ from typingutils import is_type, isinstance_typing, get_optional_type
4
4
  from types import FunctionType
5
5
  from weakref import ref
6
- from runtime.reflection.lite import reflect_function
6
+ from runtime.reflection.lite import get_signature
7
7
 
8
8
  from di.core.log import LOG
9
9
  from di.core.scope import Scope
@@ -48,19 +48,19 @@ class Container:
48
48
  return self.__default_scope
49
49
 
50
50
  @overload
51
- def add_singleton(self, service: type, /) -> None:
51
+ def add_singleton(self, service: type[Any], /) -> None:
52
52
  """Adds a singleton service to provider, which will result in same instance every time it's provided.
53
53
 
54
54
  Args:
55
- service (type): The service interface
55
+ service (type[Any]): The service interface
56
56
  """
57
57
  ...
58
58
  @overload
59
- def add_singleton(self, implementation: AnyFunction, /) -> None:
59
+ def add_singleton(self, implementation: Callable[..., T], /) -> None:
60
60
  """Adds a singleton service to provider, which will result in same instance every time it's provided.
61
61
 
62
62
  Args:
63
- implementation (AnyFunction) The service implementation
63
+ implementation (Callable[..., T]) The service implementation
64
64
  """
65
65
  ...
66
66
  @overload
@@ -87,20 +87,20 @@ class Container:
87
87
  self.__add_factory_pre(SingletonFactory, *args)
88
88
 
89
89
  @overload
90
- def add_transient(self, service: type, /) -> None:
90
+ def add_transient(self, service: type[Any], /) -> None:
91
91
  """Adds a transient service to provider, which will result in a new instance every time it's provided.
92
92
 
93
93
  Args:
94
- service (type) The service interface
94
+ service (type[Any]) The service interface
95
95
 
96
96
  """
97
97
  ...
98
98
  @overload
99
- def add_transient(self, implementation: AnyFunction, /) -> None:
99
+ def add_transient(self, implementation: Callable[..., T], /) -> None:
100
100
  """Adds a transient service to provider, which will result in a new instance every time it's provided.
101
101
 
102
102
  Args:
103
- implementation (AnyFunction) The service implementation
103
+ implementation (Callable[..., T]) The service implementation
104
104
  """
105
105
  ...
106
106
  @overload
@@ -127,25 +127,25 @@ class Container:
127
127
  self.__add_factory_pre(TransientFactory, *args)
128
128
 
129
129
  @overload
130
- def add_scoped(self, service: type, /) -> None:
130
+ def add_scoped(self, service: type[Any], /) -> None:
131
131
  """Adds a scoped service to provider, which will result in one instance every time it's provided in the same scope.
132
132
  The default scope is thread-based, and bound to the lifetime of the thread in which a given service is provided.
133
133
 
134
134
  Note: Scoped services should implement the ContextManager pattern.
135
135
 
136
136
  Args:
137
- service (type) The service interface
137
+ service (type[Any]) The service interface
138
138
  """
139
139
  ...
140
140
  @overload
141
- def add_scoped(self, implementation: AnyFunction, /) -> None:
141
+ def add_scoped(self, implementation: Callable[..., T], /) -> None:
142
142
  """Adds a scoped service to provider, which will result in one instance every time it's provided in the same scope.
143
143
  The default scope is thread-based, and bound to the lifetime of the thread in which a given service is provided.
144
144
 
145
145
  Note: Scoped services should implement the ContextManager pattern.
146
146
 
147
147
  Args:
148
- implementation (AnyFunction) The service implementation
148
+ implementation (Callable[..., T]) The service implementation
149
149
  """
150
150
  ...
151
151
  @overload
@@ -231,7 +231,7 @@ class Container:
231
231
  if not isinstance(args[0], FunctionType):
232
232
  raise AddException("Implementation must be a function or a type when no service is specified.")
233
233
  implementation = cast(Callable[..., Any], args[0])
234
- signature = reflect_function(implementation)
234
+ signature = get_signature(implementation)
235
235
  service, _ = get_optional_type(cast(type, signature.return_type))
236
236
 
237
237
  return get_service_name(service), self.__add_factory(factory_type, cast(str | type[Any], service), implementation)
@@ -248,7 +248,7 @@ class Container:
248
248
  if is_type(implementation):
249
249
  svc_type = cast(type[T], implementation)
250
250
  elif callable(implementation):
251
- signature = reflect_function(implementation)
251
+ signature = get_signature(implementation)
252
252
  svc_type = cast(type[T], signature.return_type)
253
253
  else:
254
254
  svc_type = cast(type[T], type(implementation))
@@ -9,7 +9,6 @@ from di.core.helpers import is_context, get_service_name
9
9
 
10
10
  T = TypeVar('T')
11
11
 
12
-
13
12
  class DefaultScope(Scope):
14
13
  """
15
14
  DefaultScope is as the name implies the default scope. This scope is thread-based, meaning it will supply
@@ -1,6 +1,6 @@
1
1
  from typing import TypeVar, Callable, Generic, Any, cast
2
2
  from typingutils import get_optional_type, issubclass_typing, isinstance_typing
3
- from runtime.reflection.lite import Undefined, ParameterKind, reflect_function, get_constructor
3
+ from runtime.reflection.lite import Undefined, ParameterKind, get_signature, get_constructor
4
4
 
5
5
  from di.core.scope import Scope
6
6
  from di.core.named_service import NamedService
@@ -25,7 +25,7 @@ class Factory(Generic[T]):
25
25
 
26
26
  if not implementation:
27
27
  if hasattr(service, "__origin__"):
28
- sig = reflect_function(getattr(service, "__call__"), service)
28
+ sig = get_signature(getattr(service, "__call__"), service)
29
29
  else:
30
30
  sig = get_constructor(service)
31
31
  elif isinstance(implementation, type):
@@ -37,7 +37,7 @@ class Factory(Generic[T]):
37
37
  elif isinstance_typing(implementation, service, recursive=True):
38
38
  sig = None
39
39
  elif callable(implementation):
40
- sig = reflect_function(implementation)
40
+ sig = get_signature(implementation)
41
41
  if sig.return_type:
42
42
  implementation_type, _ = get_optional_type(sig.return_type)
43
43
  else:
@@ -0,0 +1,24 @@
1
+ from __future__ import annotations
2
+ from abc import ABC, abstractmethod
3
+ from typing import Callable, TypeVar
4
+
5
+ T = TypeVar('T')
6
+
7
+ class Scope(ABC):
8
+ """
9
+ Scope is the base class from which scopes are derived, and its superclasses handle provision of
10
+ scoped services.
11
+ """
12
+
13
+ @abstractmethod
14
+ def provide(self, service: type[T], factory: Callable[[], T]) -> T:
15
+ """This function function is used by the `ScopedFactory` factory to provide and cleanup services.
16
+
17
+ Args:
18
+ service (type[T]): The service type.
19
+ factory (Callable[[], T]): The factory function.
20
+
21
+ Returns:
22
+ T: Returns an object.
23
+ """
24
+ ...
@@ -1,15 +0,0 @@
1
- from __future__ import annotations
2
- from abc import ABC, abstractmethod
3
- from typing import Callable, TypeVar
4
-
5
- T = TypeVar('T')
6
-
7
- class Scope(ABC):
8
- """
9
- Scope is the base class from which scopes are derived, and its superclasses handle provision of
10
- scoped services.
11
- """
12
-
13
- @abstractmethod
14
- def provide(self, service: type[T], factory: Callable[..., T]) -> T:
15
- ...