UNPKG

2.21 kBTypeScriptView Raw
1import { IFactory } from './IFactory';
2/**
3 * Aggregates multiple factories into a single factory component.
4 * When a new component is requested, it iterates through
5 * factories to locate the one able to create the requested component.
6 *
7 * This component is used to conveniently keep all supported factories in a single place.
8 *
9 * ### Example ###
10 *
11 * let factory = new CompositeFactory();
12 * factory.add(new DefaultLoggerFactory());
13 * factory.add(new DefaultCountersFactory());
14 *
15 * let loggerLocator = new Descriptor("*", "logger", "*", "*", "1.0");
16 * factory.canCreate(loggerLocator); // Result: Descriptor("pip-service", "logger", "null", "default", "1.0")
17 * factory.create(loggerLocator); // Result: created NullLogger
18 */
19export declare class CompositeFactory implements IFactory {
20 private _factories;
21 /**
22 * Creates a new instance of the factory.
23 *
24 * @param factories a list of factories to embed into this factory.
25 */
26 constructor(...factories: IFactory[]);
27 /**
28 * Adds a factory into the list of embedded factories.
29 *
30 * @param factory a factory to be added.
31 */
32 add(factory: IFactory): void;
33 /**
34 * Removes a factory from the list of embedded factories.
35 *
36 * @param factory the factory to remove.
37 */
38 remove(factory: IFactory): void;
39 /**
40 * Checks if this factory is able to create component by given locator.
41 *
42 * This method searches for all registered components and returns
43 * a locator for component it is able to create that matches the given locator.
44 * If the factory is not able to create a requested component is returns null.
45 *
46 * @param locator a locator to identify component to be created.
47 * @returns a locator for a component that the factory is able to create.
48 */
49 canCreate(locator: any): any;
50 /**
51 * Creates a component identified by given locator.
52 *
53 * @param locator a locator to identify component to be created.
54 * @returns the created component.
55 *
56 * @throws a CreateException if the factory is not able to create the component.
57 */
58 create(locator: any): any;
59}