beamlime.Factory#

class beamlime.Factory(*initial_prov_grs)[source]#

Dependency injection object.

Notes

Currently it does not inject dependencies for magic variables, i.e. *args and **kwargs.

__init__(*initial_prov_grs)[source]#

Initializes a factory with multiple provider groups.

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 and provider_groups.

partial_provider(product_type, *args, **kwargs)

Create a partial provider for product_type with args and kwargs and use it as a temporary provider.

temporary_provider(product_type, temp_provider)

Replace an existing provider of product_type with temp_provider or register temp_provider.

Attributes

catalogue

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 of product_type.

Return type:

Iterator[None]

local_factory(*provider_groups)[source]#

Create and yield a new factory containing a copy of self.providers and provider_groups. For existing providers, provider_groups will overwrite them.

Return type:

Iterator[Factory]

partial_provider(product_type, *args, **kwargs)[source]#

Create a partial provider for product_type with args and kwargs and use it as a temporary provider.

Return type:

Iterator[None]

temporary_provider(product_type, temp_provider)[source]#

Replace an existing provider of product_type with temp_provider or register temp_provider. temp_provider will be replaced with the original provider or removed as the context terminates.

Return type:

Iterator[None]