##// END OF EJS Templates
working on IoC configuration
working on IoC configuration

File last commit:

r113:22cf333c0b34 ioc ts support
r113:22cf333c0b34 ioc ts support
Show More
interfaces.ts
75 lines | 1.9 KiB | video/mp2t | TypeScriptLexer
/ src / main / ts / di / interfaces.ts
cin
working on IoC configuration
r113 import { isPrimitive } from "../safe";
cin
changed the project structure
r49 import { ActivationContext } from "./ActivationContext";
import { Constructor, Factory } from "../interfaces";
cin
working on IoC configuration
r113 export interface Descriptor<T = any> {
activate(context: ActivationContext, name?: string): T;
cin
changed the project structure
r49 }
cin
working on IoC configuration
r113 export function isDescriptor(x: any): x is Descriptor {
cin
changed the project structure
r49 return (!isPrimitive(x)) &&
(x.activate instanceof Function);
}
cin
working on IoC configuration
r113 export type ServiceMap<S = any> = {
[k in keyof S]: Descriptor<S[k]>;
cin
changed the project structure
r49 }
export enum ActivationType {
cin
fixed "singleton" activation type handling in container configuration...
r65 Singleton = 1,
cin
changed the project structure
r49 Container,
Hierarchy,
Context,
Call
}
cin
working on IoC configuration
r113 export interface RegistrationWithServices<S> {
services?: ServiceMap<S>;
cin
changed the project structure
r49 }
cin
working on IoC configuration
r113 export interface ServiceRegistration<T, P, S> extends RegistrationWithServices<S> {
cin
changed the project structure
r49
activation?: "singleton" | "container" | "hierarchy" | "context" | "call";
cin
working on IoC configuration
r113 params?: P;
cin
changed the project structure
r49
inject?: object | object[];
cin
working on IoC configuration
r113 cleanup?: ((instance: T) => void) | string;
cin
changed the project structure
r49 }
cin
working on IoC configuration
r113 export interface TypeRegistration<T, P, S> extends ServiceRegistration<T, P, S> {
$type: string | Constructor<T>;
cin
changed the project structure
r49 }
cin
working on IoC configuration
r113 export interface FactoryRegistration<T, P, S> extends ServiceRegistration<T, P, S> {
$factory: string | Factory<T>;
cin
changed the project structure
r49 }
cin
working on IoC configuration
r113 export interface ValueRegistration<T> {
$value: T;
cin
changed the project structure
r49 parse?: boolean;
}
cin
working on IoC configuration
r113 export interface DependencyRegistration<S, K extends keyof S> extends RegistrationWithServices<S> {
$dependency: K;
cin
changed the project structure
r49 lazy?: boolean;
optional?: boolean;
cin
working on IoC configuration
r113 default?: S[K];
cin
changed the project structure
r49 }
cin
working on IoC configuration
r113 export function isTypeRegistration(x: any): x is TypeRegistration<any, any, any> {
cin
fixed "singleton" activation type handling in container configuration...
r65 return (!isPrimitive(x)) && ("$type" in x);
cin
changed the project structure
r49 }
cin
working on IoC configuration
r113 export function isFactoryRegistration(x: any): x is FactoryRegistration<any, any, any> {
cin
fixed "singleton" activation type handling in container configuration...
r65 return (!isPrimitive(x)) && ("$factory" in x);
cin
changed the project structure
r49 }
cin
working on IoC configuration
r113 export function isValueRegistration(x: any): x is ValueRegistration<any> {
cin
changed the project structure
r49 return (!isPrimitive(x)) && ("$value" in x);
}
cin
working on IoC configuration
r113 export function isDependencyRegistration(x: any): x is DependencyRegistration<any, string | number | symbol> {
cin
changed the project structure
r49 return (!isPrimitive(x)) && ("$dependency" in x);
}