beamlime.SingletonProvider#

class beamlime.SingletonProvider(_constructor, /, *args, **kwargs)[source]#

Singleton provider always returns the same instance.

Therefore passing different arguments from the first call is not allowed. functools.lru_cache is used to check if the hashable arguments are the same. For unhashable arguments, cached_arguments_filter check if they are the same instances.

SingletonProvider is needed for sharing the same object by multiple objects. The arguments filter prioritizes instance equality over hash equality. If the hashable arguments check is not compatible, consider providing the dependencies also as singletons.

Raises:

SingletonProviderCalledWithDifferentArgs – If the provider is called with different argument from the first call.

__init__(_constructor, /, *args, **kwargs)[source]#

Notes

Nested Provider or partial as a constructor is forbidden similar to partial.

Methods

__init__(_constructor, /, *args, **kwargs)

Notes

can_provide(product_type)

Check if the given product_type can be supported by this provider.

Attributes

call_name

constructor