##// END OF EJS Templates
sync
sync

File last commit:

r115:691199f665e0 ioc ts support
r117:6149d2260004 ioc ts support
Show More
interfaces.ts
88 lines | 2.4 KiB | video/mp2t | TypeScriptLexer
/ src / main / ts / di / interfaces.ts
cin
corrected code to support ts strict mode...
r115 import { isPrimitive, primitive } from "../safe";
cin
changed the project structure
r49 import { ActivationContext } from "./ActivationContext";
import { Constructor, Factory } from "../interfaces";
cin
corrected code to support ts strict mode...
r115 export interface Descriptor<S = any, T = any> {
activate(context: ActivationContext<S>): 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
corrected code to support ts strict mode...
r115 export type ServiceMap<S, S2 extends S = S> = {
[k in keyof S2]: Descriptor<S, S2[k]>;
};
export type PartialServiceMap<S, S2 extends S = S> = Partial<ServiceMap<S, S2>>;
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
corrected code to support ts strict mode...
r115 export type Parse<T> = T extends primitive ? T:
T extends Descriptor<infer V> ? V :
{ [K in keyof T]: Parse<T[K]> };
export interface Resolver<S> {
resolve<K extends keyof ContainerServices<S>, T extends ContainerServices<S>[K] = ContainerServices<S>[K]>(name: K, def?: T): T;
}
export type ContainerServices<S> = S & {
container: Resolver<S>;
};
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
r114 export function isDependencyRegistration<S>(x: any): x is DependencyRegistration<S, keyof S> {
cin
changed the project structure
r49 return (!isPrimitive(x)) && ("$dependency" in x);
}