anydi 0.37.1__tar.gz → 0.37.3__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.
- {anydi-0.37.1 → anydi-0.37.3}/PKG-INFO +1 -1
- {anydi-0.37.1 → anydi-0.37.3}/anydi/_container.py +12 -5
- {anydi-0.37.1 → anydi-0.37.3}/pyproject.toml +1 -1
- {anydi-0.37.1 → anydi-0.37.3}/LICENSE +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/README.md +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/__init__.py +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/_context.py +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/_provider.py +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/_types.py +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/_utils.py +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/ext/__init__.py +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/ext/_utils.py +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/ext/django/__init__.py +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/ext/django/_container.py +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/ext/django/_settings.py +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/ext/django/_utils.py +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/ext/django/apps.py +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/ext/django/middleware.py +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/ext/django/ninja/__init__.py +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/ext/django/ninja/_operation.py +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/ext/django/ninja/_signature.py +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/ext/fastapi.py +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/ext/faststream.py +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/ext/pydantic_settings.py +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/ext/pytest_plugin.py +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/ext/starlette/__init__.py +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/ext/starlette/middleware.py +0 -0
- {anydi-0.37.1 → anydi-0.37.3}/anydi/py.typed +0 -0
|
@@ -86,11 +86,13 @@ class Container:
|
|
|
86
86
|
modules: Sequence[Module | type[Module] | Callable[[Container], None] | str]
|
|
87
87
|
| None = None,
|
|
88
88
|
strict: bool = False,
|
|
89
|
+
default_scope: Scope = "transient",
|
|
89
90
|
testing: bool = False,
|
|
90
91
|
logger: logging.Logger | None = None,
|
|
91
92
|
) -> None:
|
|
92
93
|
self._providers: dict[type[Any], Provider] = {}
|
|
93
94
|
self._strict = strict
|
|
95
|
+
self._default_scope = default_scope
|
|
94
96
|
self._testing = testing
|
|
95
97
|
self._logger = logger or logging.getLogger(__name__)
|
|
96
98
|
self._resources: dict[str, list[type[Any]]] = defaultdict(list)
|
|
@@ -121,6 +123,11 @@ class Container:
|
|
|
121
123
|
"""Check if strict mode is enabled."""
|
|
122
124
|
return self._strict
|
|
123
125
|
|
|
126
|
+
@property
|
|
127
|
+
def default_scope(self) -> Scope:
|
|
128
|
+
"""Get the default scope."""
|
|
129
|
+
return self._default_scope
|
|
130
|
+
|
|
124
131
|
@property
|
|
125
132
|
def testing(self) -> bool:
|
|
126
133
|
"""Check if testing mode is enabled."""
|
|
@@ -221,7 +228,7 @@ class Container:
|
|
|
221
228
|
# Try to detect scope
|
|
222
229
|
if scope is None:
|
|
223
230
|
scope = self._detect_scope(interface, **defaults)
|
|
224
|
-
scope = scope or
|
|
231
|
+
scope = scope or self.default_scope
|
|
225
232
|
provider = Provider(call=interface, scope=scope, interface=interface)
|
|
226
233
|
return self._register_provider(provider, False, **defaults)
|
|
227
234
|
raise
|
|
@@ -622,7 +629,7 @@ class Container:
|
|
|
622
629
|
|
|
623
630
|
# Try to get instance from defaults
|
|
624
631
|
if parameter.name in defaults:
|
|
625
|
-
|
|
632
|
+
return defaults[parameter.name]
|
|
626
633
|
|
|
627
634
|
# Try to get instance from context
|
|
628
635
|
elif context and parameter.annotation in context:
|
|
@@ -635,7 +642,7 @@ class Container:
|
|
|
635
642
|
except LookupError:
|
|
636
643
|
if parameter.default is inspect.Parameter.empty:
|
|
637
644
|
raise
|
|
638
|
-
|
|
645
|
+
return parameter.default
|
|
639
646
|
|
|
640
647
|
# Wrap the instance in a proxy for testing
|
|
641
648
|
if self.testing:
|
|
@@ -666,7 +673,7 @@ class Container:
|
|
|
666
673
|
|
|
667
674
|
# Try to get instance from defaults
|
|
668
675
|
if parameter.name in defaults:
|
|
669
|
-
|
|
676
|
+
return defaults[parameter.name]
|
|
670
677
|
|
|
671
678
|
# Try to get instance from context
|
|
672
679
|
elif context and parameter.annotation in context:
|
|
@@ -679,7 +686,7 @@ class Container:
|
|
|
679
686
|
except LookupError:
|
|
680
687
|
if parameter.default is inspect.Parameter.empty:
|
|
681
688
|
raise
|
|
682
|
-
|
|
689
|
+
return parameter.default
|
|
683
690
|
|
|
684
691
|
# Wrap the instance in a proxy for testing
|
|
685
692
|
if self.testing:
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|