pip_services3_components.build.CompositeFactory module


Composite factory implementation


Conceptual Vision Consulting LLC 2018-2019, see AUTHORS for more details.


MIT, see LICENSE for more details.

class pip_services3_components.build.CompositeFactory.CompositeFactory(*factories: pip_services3_components.build.IFactory.IFactory)

Bases: pip_services3_components.build.IFactory.IFactory

Aggregates multiple factories into a single factory component. When a new component is requested, it iterates through factories to locate the one able to create the requested component.

This component is used to conveniently keep all supported factories in a single place.


factory = CompositeFactory()
factory.add(new DefaultLoggerFactory())
factory.add(new DefaultCountersFactory())

loggerLocator = Descriptor("*", "logger", "*", "*", "1.0")
factory.can_create(loggerLocator)  # Result: Descriptor("pip-service", "logger", "null", "default", "1.0")
factory.create(loggerLocator)      # Result: created NullLogger
add(factory: pip_services3_components.build.IFactory.IFactory)

Adds a factory into the list of embedded factories.


factory – a factory to be added.

can_create(locator: Any) → Any

Checks if this factory is able to create component by given locator.

This method searches for all registered components and returns a locator for component it is able to create that matches the given locator. If the factory is not able to create a requested component is returns null.


locator – a locator to identify component to be created.


a locator for a component that the factory is able to create.

create(locator: Any) → Any

Creates a component identified by given locator.


locator – a locator to identify component to be created.


the created component.

remove(factory: pip_services3_components.build.IFactory.IFactory)

Removes a factory from the list of embedded factories.


factory – the factory to remove.