-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServiceResolutionContext.ts
46 lines (42 loc) · 1.56 KB
/
ServiceResolutionContext.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import type {
NamedServiceKey,
ServiceKey,
ServiceResolver,
ServicesMap,
} from "./ServiceResolver";
/**
* Service resolution context object interface. This interface is passed to ServiceFactory.
*/
export interface ServiceResolutionContext<TServicesMap extends ServicesMap>
extends ServiceResolver<TServicesMap> {
/**
* Returns array of service resolution stack, which has records of services stack being resolved in current request.
* The first element (at index 0) is the root service, for which dependencies are resolved. The last element is
* service name, being resolved at the moment (which ServiceFactory is called).
*/
getStack(): NamedServiceKey<TServicesMap>[];
/**
* Returns true, when current service is being resolved as ancestor dependency for given service key. Ignores
* service name, while checking, if 'name' argument is omitted.
*
* @param key
* @param name
*/
isResolvingFor(key: ServiceKey<TServicesMap>, name?: string): boolean;
/**
* Returns true, when current service is being resolved directly for service of given key. Ignores service name,
* if 'name' argument is omitted.
*
* @param key
* @param name
*/
isDirectlyResolvingFor(key: ServiceKey<TServicesMap>, name?: string): boolean;
/**
* Delays given callback. The callback will be executed after current dependencies stack is resolved.
* Used to resolve circular dependencies.
* IMPORTANT: circular dependencies must have "request" or "singleton" lifecycle.
*
* @param callback
*/
delay(callback: () => void): void;
}