##// END OF EJS Templates
working on typings
working on typings

File last commit:

r8:80cb5668e4a7 default
r8:80cb5668e4a7 default
Show More
FluentConfiguration.ts
71 lines | 2.7 KiB | video/mp2t | TypeScriptLexer
/ src / main / ts / FluentConfiguration.ts
cin
initial commit
r0 import { DescriptorBuilder } from "./DescriptorBuilder";
cin
Working on container builder
r5 import { ConfigurableKeys, ContainerServices, RegistrationBuildersMap, ExtractRequired, IContainerBuilder } from "./interfaces";
cin
working on fluent configuration
r1 import { ServiceContainer } from "./interfaces";
import { argumentNotNull, each, isKey } from "./traits";
cin
initial commit
r0
cin
working on typings
r8 export class FluentConfiguration<S, Y extends ConfigurableKeys<S> = ConfigurableKeys<S>> {
cin
initial commit
r0
cin
code comments
r2 private _builders: Partial<RegistrationBuildersMap<S>> = {};
cin
initial commit
r0
cin
code comments
r2 /** Adds a declaration of the services to the current config.
*
* @template D The map of the services
* @returns self
*/
cin
working on typings
r8 declare<D extends Pick<S, keyof D & keyof S>>(): FluentConfiguration<S & D, Y | ConfigurableKeys<D>> {
cin
working on fluent configuration
r1 return this as FluentConfiguration<S & D, Y | ConfigurableKeys<D>>;
cin
initial commit
r0 }
cin
code comments
r2 /** Adds compile-time information about the already provided services
*
* @template P The map of the provided services
* @returns self
*/
cin
working on fluent configuration
r1 provided<P extends Pick<S, keyof P & keyof S>>(): FluentConfiguration<S & P, Exclude<Y, keyof P>> {
return this as FluentConfiguration<S & P, Exclude<Y, keyof P>>;
}
cin
code comments
r2 /** Register the service.
*
* @param name The name of the service
* @param builder The service builder
* @returns self
*/
cin
working on fluent configuration
r1 register<K extends Y>(name: K, builder: RegistrationBuildersMap<S>[K]): FluentConfiguration<S, Exclude<Y, K>>;
cin
code comments
r2 /** Registers the collection of services
* @param config The collection of services to register.
* @returns self
*/
cin
working on fluent configuration
r1 register<K extends Y>(config: RegistrationBuildersMap<S, K>): FluentConfiguration<S, Exclude<Y, K>>;
register<K extends Y>(nameOrConfig: K | RegistrationBuildersMap<S, K>, builder?: RegistrationBuildersMap<S>[K]) {
if (isKey(nameOrConfig)) {
cin
initial commit
r0 argumentNotNull(builder, "builder");
this._builders[nameOrConfig] = builder;
} else {
each(nameOrConfig, (v, k) => this.register(k, v));
}
cin
working on fluent configuration
r1 return this as FluentConfiguration<S, Exclude<Y, K>>;
}
cin
code comments
r2 /**
* This method is used to enable a compile time check of the configuration.
* If there are not configured services in the configuration the compiler
* will trigger the error.
*
* @param missing Empty object literal should always be specified.
* @returns self
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
done<M extends ExtractRequired<S,Y>>(missing: M) {
cin
initial commit
r0 return this;
}
cin
Working on container builder
r5 configure<T extends IContainerBuilder<S>>(builder: T) {
cin
working on fluent configuration
r1 each(this._builders, (v, k) => {
cin
Working on container builder
r5 v(builder.createServiceBuilder(k));
cin
initial commit
r0 });
cin
Working on container builder
r5 builder.build() as T & ServiceContainer<S>;
cin
initial commit
r0 }
}