Factory¶
uzi.providers.Factory
¶
Bases: Provider[abc.Callable[..., T_Injected], nodes._T_FactoryNode]
, t.Generic[T_Injected, nodes._T_FactoryNode]
Resolves to the return value of the given factory. A factory can be a
type
, function
or a Callable
object.
The factory is called every time a dependency for this provider is requested.
Attributes:
Name | Type | Description |
---|---|---|
concrete |
Union[type[T_Injected], abc.Callable[..., T_Injected]]
|
the factory to used to create the provided value. |
arguments |
tuple[tuple.frozendict]
|
A tuple of positional and keyword arguments passed to the factory. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
concrete |
Union[type[T_Injected], abc.Callable[..., T_Injected]]
|
the factory. Can be a |
None
|
*args |
Union[Dep, Any]
|
Positional arguments to pass to the factory. |
()
|
**kwargs |
Union[Dep, Any]
|
Keyword arguments to pass to the factory. |
{}
|
With Arguments¶
Positional and/or keyword arguments to pass to the factory may be provided.
Values Only¶
1 2 |
|
Values and Dependencies¶
Arguments of type DependencyMarker
will automatically be resolved and passed to the factory while calling it.
1 2 3 4 5 6 7 8 9 |
|
asynchronous(is_async: bool = True) -> Self
¶
Mark/Unmark this provider as asynchronous. Updates is_async
attribute.
Normally, coroutines
and factories with async
dependencies automatically
detected as asynchronous. This method provides the ability to change this
default behaviour.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
is_async |
Union[bool, None]
|
|
True
|
Returns:
Name | Type | Description |
---|---|---|
self |
Provider
|
this provider |
args(*args) -> Self
¶
kwargs(**kwargs) -> Self
¶
use(concrete, *args, **kwargs)
¶
Sets the provider's factory and arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
concrete |
Union[type[T_Injected], abc.Callable[..., T_Injected]]
|
the factory. Can be a |
required |
*args |
Union[Dep, Any]
|
Positional arguments to pass to the factory. |
()
|
**kwargs |
Union[Dep, Any]
|
Keyword arguments to pass to the factory. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
self |
Factory
|
this provider |