beamlime.constructors.factories.Factory#
- class beamlime.constructors.factories.Factory(*initial_prov_grs)[source]#
Dependency injection object.
Notes
Currently it does not inject dependencies for magic variables, i.e.
*args
and**kwargs
.Methods
__init__
(*initial_prov_grs)Initializes a factory with multiple provider groups.
constant_provider
(product_type, hardcoded_value)Use a lambda function that returns
hardcoded_value
.local_factory
(*provider_groups)Create and yield a new factory containing a copy of
self.providers
andprovider_groups
.partial_provider
(product_type, *args, **kwargs)Create a partial provider for
product_type
withargs
andkwargs
and use it as a temporary provider.temporary_provider
(product_type, temp_provider)Replace an existing provider of
product_type
withtemp_provider
or registertemp_provider
.Attributes
Frozen set of the product type(s) this factory can manufacture.
- __getitem__(product_type)[source]#
Build an object of
product_type
using the registered providers.- Return type:
TypeVar
(Product
)
Notes
Currently position-only argument dependencies are not supported. It only builds the keyword argument dependencies and attribute dependencies for the provider.
TODO: Detect cyclic dependencies earlier.
- property catalogue: frozenset[type[Product]]#
Frozen set of the product type(s) this factory can manufacture.
- constant_provider(product_type, hardcoded_value)[source]#
Use a lambda function that returns
hardcoded_value
. as a temporary provider ofproduct_type
.
- local_factory(*provider_groups)[source]#
Create and yield a new factory containing a copy of
self.providers
andprovider_groups
. For existing providers,provider_groups
will overwrite them.