1 | /** @module build */
|
2 | import { IFactory } from './IFactory';
|
3 | /**
|
4 | * Basic component factory that creates components using registered types and factory functions.
|
5 | *
|
6 | * #### Example ###
|
7 | *
|
8 | * let factory = new Factory();
|
9 | *
|
10 | * factory.registerAsType(
|
11 | * new Descriptor("mygroup", "mycomponent1", "default", "*", "1.0"),
|
12 | * MyComponent1
|
13 | * );
|
14 | * factory.register(
|
15 | * new Descriptor("mygroup", "mycomponent2", "default", "*", "1.0"),
|
16 | * (locator) => {
|
17 | * return new MyComponent2();
|
18 | * }
|
19 | * );
|
20 | *
|
21 | * factory.create(new Descriptor("mygroup", "mycomponent1", "default", "name1", "1.0"))
|
22 | * factory.create(new Descriptor("mygroup", "mycomponent2", "default", "name2", "1.0"))
|
23 | *
|
24 | * @see [[https://pip-services3-node.github.io/pip-services3-commons-node/classes/refer.descriptor.html Descriptor]]
|
25 | * @see [[IFactory]]
|
26 | */
|
27 | export declare class Factory implements IFactory {
|
28 | private _registrations;
|
29 | /**
|
30 | * Registers a component using a factory method.
|
31 | *
|
32 | * @param locator a locator to identify component to be created.
|
33 | * @param factory a factory function that receives a locator and returns a created component.
|
34 | */
|
35 | register(locator: any, factory: (locator: any) => any): void;
|
36 | /**
|
37 | * Registers a component using its type (a constructor function).
|
38 | *
|
39 | * @param locator a locator to identify component to be created.
|
40 | * @param type a component type.
|
41 | */
|
42 | registerAsType(locator: any, type: any): void;
|
43 | /**
|
44 | * Checks if this factory is able to create component by given locator.
|
45 | *
|
46 | * This method searches for all registered components and returns
|
47 | * a locator for component it is able to create that matches the given locator.
|
48 | * If the factory is not able to create a requested component is returns null.
|
49 | *
|
50 | * @param locator a locator to identify component to be created.
|
51 | * @returns a locator for a component that the factory is able to create.
|
52 | */
|
53 | canCreate(locator: any): any;
|
54 | /**
|
55 | * Creates a component identified by given locator.
|
56 | *
|
57 | * @param locator a locator to identify component to be created.
|
58 | * @returns the created component.
|
59 | *
|
60 | * @throws a CreateException if the factory is not able to create the component.
|
61 | */
|
62 | create(locator: any): any;
|
63 | }
|