Resolver module
tidi.resolver
Finds or creates dependency instances based on availability and options.
DependencyResolutionError
ResolverOptions
dataclass
Options that control how resolving is done.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
use_registry |
bool
|
whether to try using the registry or not. |
required |
initialise_missing |
bool
|
whether to try to initialise the dependency or not. |
required |
Source code in src/tidi/resolver.py
resolve_dependency(type_, resolver_options, registry=None, provider=None)
Returns a dependency according to configured options.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_ |
Type[T]
|
the type of the dependency being looked for. |
required |
resolver_options |
ResolverOptions
|
options dictating how to resolve the dependency. |
required |
registry |
Registry | None
|
an optional registry containing the dependency. Defaults to None. |
None
|
provider |
Callable[..., T] | Callable[..., AbstractContextManager[T]] | None
|
(t.Callable[..., T] | typing.Callable[..., contextlib.AbstractContextManager[T]] | None): an optional context manager function that returns the dependency. Defaults to None. |
None
|
Raises:
Type | Description |
---|---|
DependencyResolutionError
|
if a registry is required but not provided |
DependencyResolutionError
|
if the function doesn't know how to handle the situation |
Returns:
Type | Description |
---|---|
type requested (T)
|
an instance of the dependency requested. |