##// END OF EJS Templates
Added tag v1.4.0-rc2 for changeset 93d9db76884e
Added tag v1.4.0-rc2 for changeset 93d9db76884e

File last commit:

r135:03e32ec7c20b ioc ts support
r141:64dfb0328301 default
Show More
interfaces.ts
53 lines | 1.7 KiB | video/mp2t | TypeScriptLexer
import { ActivationContext } from "./ActivationContext";
export interface Descriptor<S extends object = any, T = any> {
activate(context: ActivationContext<S>): T;
}
export type ServiceMap<S extends object> = {
[k in keyof S]: Descriptor<S, S[k]>;
};
export type ContainerKeys<S extends object> = keyof S | keyof ContainerProvided<S>;
export type TypeOfService<S extends object, K> =
K extends keyof ContainerProvided<S> ? ContainerProvided<S>[K] :
K extends keyof S ? S[K] : never;
export type ContainerServiceMap<S extends object> = {
[K in ContainerKeys<S>]: Descriptor<S, TypeOfService<S, K>>;
};
export type PartialServiceMap<S extends object> = {
[k in keyof S]?: Descriptor<S, S[k]>;
};
export interface ServiceLocator<S extends object> {
resolve<K extends ContainerKeys<S>>(name: K, def?: TypeOfService<S, K>): TypeOfService<S, K>;
}
export interface ContainerProvided<S extends object> {
container: ServiceLocator<S>;
}
export type ContainerRegistered<S extends object> = /*{
[K in Exclude<keyof S, keyof ContainerProvided<S>>]: S[K];
};*/
Exclude<S, ContainerProvided<S>>;
export type ActivationType = "singleton" | "container" | "hierarchy" | "context" | "call";
/**
* Интерфейс для управления жизнью экземпляра объекта. Каждая регистрация имеет
* свой собственный объект `ILifetime`, который создается при первой активации
*/
export interface ILifetime {
/** Проверяет, что уже создан экземпляр объекта */
has(): boolean;
get(): any;
initialize(context: ActivationContext<any>): void;
store(item: any, cleanup?: (item: any) => void): void;
}