interfaces.ts
71 lines
| 1.6 KiB
| video/mp2t
|
TypeScriptLexer
|
|
r34 | import { isNull } from "../safe"; | ||
| import { ActivationContext } from "./ActivationContext"; | ||||
| export interface Descriptor { | ||||
| activate(context: ActivationContext, name?: string); | ||||
|
|
r38 | isInstanceCreated(): boolean; | ||
| getInstance(); | ||||
|
|
r34 | } | ||
| export type Constructor<T = {}> = new (...args: any[]) => T; | ||||
| export type Factory<T = {}> = (...args: any[]) => T; | ||||
| export function isDescriptor(instance): instance is Descriptor { | ||||
|
|
r38 | return (!isNull(instance)) && | ||
| ("activate" in instance); | ||||
|
|
r34 | } | ||
| export interface ServiceMap { | ||||
|
|
r38 | [s: string]: Descriptor; | ||
|
|
r34 | } | ||
| export enum ActivationType { | ||||
|
|
r38 | Singleton, | ||
| Container, | ||||
| Hierarchy, | ||||
| Context, | ||||
| Call | ||||
| } | ||||
| export interface RegistrationWithServices { | ||||
| services?: object; | ||||
| } | ||||
| export interface ServiceRegistration extends RegistrationWithServices { | ||||
| $type?: string | Constructor; | ||||
| $factory?: string | Factory; | ||||
| activation?: "singleton" | "container" | "hierarchy" | "context" | "call"; | ||||
| params?; | ||||
| inject?: object | object[]; | ||||
| cleanup: (instance) => void | string; | ||||
| } | ||||
| export interface ValueRegistration { | ||||
| $value; | ||||
| parse?: boolean; | ||||
| } | ||||
| export interface DependencyRegistration extends RegistrationWithServices { | ||||
| $dependency: string; | ||||
| lazy?: boolean; | ||||
| optional?: boolean; | ||||
| default?; | ||||
| } | ||||
| export function isServiceRegistration(x): x is ServiceRegistration { | ||||
| return x && ("$type" in x || "$factory" in x); | ||||
| } | ||||
| export function isValueRegistration(x): x is ValueRegistration { | ||||
| return x && "$value" in x; | ||||
| } | ||||
| export function isDependencyRegistration(x): x is DependencyRegistration { | ||||
| return x && "$depdendency" in x; | ||||
| } | ||||
