##// END OF EJS Templates
Working on container builder
Working on container builder

File last commit:

r5:83fa5814462d default
r5:83fa5814462d default
Show More
interfaces.ts
146 lines | 6.1 KiB | video/mp2t | TypeScriptLexer
cin
working on fluent configuration
r1 import { ActivationContext } from "./ActivationContext";
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4 import { key } from "./traits";
cin
working on fluent configuration
r1
cin
initial commit
r0 export interface IDestroyable {
destroy(): void;
}
cin
working on fluent configuration
r1 /**
* @template S Карта доступных зависимостей
*/
cin
initial commit
r0 export interface Resolver<S extends object> {
cin
working on fluent configuration
r1 /**
* Функция для разрешения зависимостей, поддерживает создание фабричных методов,
* отложенную активацию и значение по-умолчанию для сервисов
* @template K Ключ сервиса из {@link S}
* @template O Тип параметра {@link opts} используется для выведения типа
* возвращаемого значения.
* @param name Ключ сервиса, который будет разрешен.
* @param {boolean=} opts.lazy Признак того, что требуется отложенная активация,
* будет возвращен фабричный метод для получения зависимости. Если не указан,
* то считается `false`.
* @param {any=} opts.default Значение по умолчанию, если в контейнере указанный
* сервис не зарегистрирован
* @returns Либо фабричный метод для получения зависимости, либо значение зависимости
* @throws Error Если зависимость не найдена и не предоставлено значение по-умолчанию
*/
<K extends keyof S, O extends { lazy: true; default?: unknown }>(name: K, opts?: O): () => (O extends { default: infer T } ? T : never) | NonNullable<S[K]>;
<K extends keyof S, O extends { lazy?: false; default?: unknown }>(name: K, opts?: O): (O extends { default: infer T } ? T : never) | NonNullable<S[K]>;
cin
initial commit
r0 }
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4 export type DepsMap<K extends key, SK extends key> = { [k in K]: SK | Ref<SK, boolean, unknown> };
cin
Working on container builder
r5 export type Ref<K extends key, L extends boolean, D> = { name: K, lazy?: L } | { name: K, lazy?: L, default: D };
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4
export type Resolved<S, K extends keyof S, L, D> =
cin
Working on container builder
r5 L extends true ? () => NonNullable<S[K]> | (unknown extends D ? never : D) : NonNullable<S[K]> | (unknown extends D ? never : D);
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4
export interface IDescriptorBuilder<S extends object, T, R extends object = object> {
cin
working on fluent configuration
r1
/**
*
* @param f
*/
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4 factory(f: (refs: R) => T): void;
wants<X extends DepsMap<Exclude<key, keyof R>, keyof S>>(refs: X):
IDescriptorBuilder<S, T, R & {
[k in keyof X]:
X[k] extends keyof S ? NonNullable<S[X[k]]> :
cin
Working on container builder
r5 X[k] extends Ref<infer K, infer L, infer D> ? Resolved<S, K & keyof S, L, D> :
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4 never
}>
cin
initial commit
r0
cin
working on fluent configuration
r1 override<K extends ConfigurableKeys<S>>(name: K, builder: RegistrationBuilder<S, NonNullable<S[K]>>): this;
override<K extends ConfigurableKeys<S>>(services: { [name in K]: RegistrationBuilder<S, NonNullable<S[K]>> }): this;
cin
initial commit
r0
cin
working on fluent configuration
r1 lifetime(lifetime: "singleton", typeId: string | number | object): this;
lifetime(lifetime: ILifetime<T> | Exclude<ActivationType, "singleton">): this;
cin
initial commit
r0
cleanup(cb: (item: T) => void): this;
value(v: T): void;
}
cin
Removed ContextResolver, added DescriptoBuilder.wants(...), dependencies are declared statically
r4 export type RegistrationBuilder<S extends object, T> = (d: IDescriptorBuilder<S, T>) => void;
cin
initial commit
r0
cin
working on fluent configuration
r1 export type RegistrationBuildersMap<S extends object, K extends ConfigurableKeys<S> = ConfigurableKeys<S>> = {
cin
Working on container builder
r5 [k in K]-?: RegistrationBuilder<ContainerServices<S>, NonNullable<S[k]>>
cin
working on fluent configuration
r1 };
cin
initial commit
r0
cin
working on fluent configuration
r1 export interface Descriptor<S extends object, T> {
cin
Working on container builder
r5 activate(context: IActivationContext<S>): T;
cin
initial commit
r0 }
cin
Working on container builder
r5 export interface IActivationContext<S extends object> extends ServiceLocator<S> {
createLifetime<T>(): ILifetime<T>;
createContainerLifetime<T>(): ILifetime<T>;
}
export type ConfigurableDescriptor<S extends object, K extends ConfigurableKeys<S>> = Descriptor<ContainerServices<S>, S[K]>;
cin
initial commit
r0
cin
working on fluent configuration
r1 export type RegistrationMap<S extends object, K extends keyof S = keyof S> = {
[k in K]-?: Descriptor<S, S[k]>;
cin
initial commit
r0 };
cin
Working on container builder
r5 export interface ContainerProvided<S extends Configurable<S>> {
cin
working on fluent configuration
r1 container: ServiceLocator<ContainerServices<S>>;
cin
Working on container builder
r5 childContainer: IContainerBuilder<S>;
cin
working on fluent configuration
r1 }
cin
Working on container builder
r5 export type Configurable<S> = { [k in keyof S & (keyof ContainerProvided<never>)]: never; };
cin
working on fluent configuration
r1
cin
Working on container builder
r5 export type ProvidedKeys = keyof ContainerProvided<never>;
cin
working on fluent configuration
r1
cin
Working on container builder
r5 export type ContainerServices<S extends Configurable<S>> = S & ContainerProvided<S>;
cin
working on fluent configuration
r1
export type ConfigurableKeys<S extends object> = Exclude<keyof S, ProvidedKeys>;
export type ConfigurableServices<S extends object> = Pick<S, ConfigurableKeys<S>>;
cin
initial commit
r0
cin
Working on container builder
r5 export type ContainerKeys<S extends Configurable<S>> = keyof S | keyof ContainerProvided<never>;
cin
initial commit
r0 export interface ServiceLocator<S extends object> {
cin
working on fluent configuration
r1 resolve<K extends keyof S>(name: K): NonNullable<S[K]>;
resolve<K extends keyof S, T>(name: K, def: T): NonNullable<S[K]> | T;
cin
initial commit
r0 }
cin
working on fluent configuration
r1 export interface LifetimeContainer {
createLifetime<T>(): ILifetime<T>;
}
cin
Working on container builder
r5 export interface ServiceContainer<S extends Configurable<S>> extends
ServiceLocator<ContainerServices<S>>,
IDestroyable {
cin
working on fluent configuration
r1
cin
Working on container builder
r5 createChildContainer(): IContainerBuilder<S>;
}
cin
initial commit
r0
cin
Working on container builder
r5 export interface IContainerBuilder<S extends Configurable<S>> {
createServiceBuilder<K extends keyof S>(name: K): IDescriptorBuilder<S, NonNullable<S[K]>>;
build(): ServiceContainer<S>;
cin
initial commit
r0 }
export type ActivationType = "singleton" | "container" | "hierarchy" | "context" | "call";
/**
* Интерфейс для управления жизнью экземпляра объекта. Каждая регистрация имеет
* свой собственный объект `ILifetime`, который создается при первой активации
*/
cin
working on fluent configuration
r1 export interface ILifetime<T> {
cin
initial commit
r0 /** Проверяет, что уже создан экземпляр объекта */
has(): boolean;
cin
working on fluent configuration
r1 get(): T;
cin
Working on container builder
r5 initialize(context: IActivationContext<object>): void;
cin
initial commit
r0
cin
working on fluent configuration
r1 store(item: T, cleanup?: (item: T) => void): void;
}
cin
initial commit
r0
cin
code comments
r2 export type ExtractRequired<T, K extends keyof T = keyof T> = { [p in K as (undefined extends T[p] ? never : p)]-?: T[p] };
cin
working on fluent configuration
r1