UNPKG

1.73 kBTypeScriptView Raw
1import { Constructable } from '../types/constructable.type';
2import { ServiceIdentifier } from '../types/service-identifier.type';
3/**
4 * Service metadata is used to initialize service and store its state.
5 */
6export interface ServiceMetadata<Type = unknown> {
7 /** Unique identifier of the referenced service. */
8 id: ServiceIdentifier;
9 /**
10 * Class definition of the service what is used to initialize given service.
11 * This property maybe null if the value of the service is set manually.
12 * If id is not set then it serves as service id.
13 */
14 type: Constructable<Type> | null;
15 /**
16 * Indicates if this service must be global and same instance must be used across all containers.
17 */
18 global: boolean;
19 /**
20 * Indicates whether a new instance of this class must be created for each class injecting this class.
21 * Global option is ignored when this option is used.
22 */
23 transient: boolean;
24 /**
25 * Allows to setup multiple instances the different classes under a single service id string or token.
26 */
27 multiple: boolean;
28 /**
29 * Indicates whether a new instance should be created as soon as the class is registered.
30 * By default the registered classes are only instantiated when they are requested from the container.
31 */
32 eager?: boolean;
33 /**
34 * Factory function used to initialize this service.
35 * Can be regular function ("createCar" for example),
36 * or other service which produces this instance ([CarFactory, "createCar"] for example).
37 */
38 factory: [Constructable<unknown>, string] | CallableFunction | undefined;
39 /**
40 * Instance of the target class.
41 */
42 value: unknown | Symbol;
43}