pip_services3_components.build.Factory module

pip_services3_components.build.Factory

Factory implementation

copyright

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

license

MIT, see LICENSE for more details.

class pip_services3_components.build.Factory.Factory

Bases: pip_services3_components.build.IFactory.IFactory

Basic component factory that creates components using registered types and factory functions.

Example:

factory = Factory()

factory.registerAsType(Descriptor("mygroup", "mycomponent1", "default", "*", "1.0"), MyComponent1)

factory.create(Descriptor("mygroup", "mycomponent1", "default", "name1", "1.0"))
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.

Parameters

locator – a locator to identify component to be created.

Returns

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

create(locator: Any) → Any

Creates a component identified by given locator.

Parameters

locator – a locator to identify component to be created.

Returns

the created component.

register(locator: Any, factory: Any)

Registers a component using a factory method.

Parameters
  • locator – a locator to identify component to be created.

  • factory – a factory function that receives a locator and returns a created component.

register_as_type(locator: Any, component_type: Any)

Registers a component using its type (a constructor function).

Parameters
  • locator – a locator to identify component to be created.

  • component_type – a component type.

class pip_services3_components.build.Factory.Registration(locator, factory)

Bases: object

factory = None
locator = None