##// END OF EJS Templates
added provided and configure methods to the fluent container configuration, added applyConfig method to the container
added provided and configure methods to the fluent container configuration, added applyConfig method to the container

File last commit:

r142:be7edf08a115 v1.4.0-rc3 default
r142:be7edf08a115 v1.4.0-rc3 default
Show More
FluentConfiguration.ts
68 lines | 2.3 KiB | video/mp2t | TypeScriptLexer
/ src / main / ts / di / fluent / FluentConfiguration.ts
cin
Completely removed IoC annotations...
r135 import { Container } from "../Container";
import { argumentNotNull, each, isPrimitive, isPromise } from "../../safe";
import { DescriptorBuilder } from "./DescriptorBuilder";
cin
added provided and configure methods to the fluent container configuration, added applyConfig method to the container
r142 import { RegistrationBuilder, FluentRegistrations, ContainerConfiguration } from "./interfaces";
cin
Completely removed IoC annotations...
r135 import { Cancellation } from "../../Cancellation";
export class FluentConfiguration<S extends object, Y extends keyof S = keyof S> {
_builders: { [k in keyof S]?: RegistrationBuilder<S, S[k]> } = {};
cin
added provided and configure methods to the fluent container configuration, added applyConfig method to the container
r142 provided<K extends Y>(): FluentConfiguration<S, Exclude<Y, K>> {
return this;
}
cin
Completely removed IoC annotations...
r135 register<K extends Y>(name: K, builder: RegistrationBuilder<S, S[K]>): FluentConfiguration<S, Exclude<Y, K>>;
register<K extends Y>(config: FluentRegistrations<K, S>): FluentConfiguration<S, Exclude<Y, K>>;
register<K extends Y>(nameOrConfig: K | FluentRegistrations<K, S>, builder?: RegistrationBuilder<S, S[K]>): FluentConfiguration<S, Exclude<Y, K>> {
if (isPrimitive(nameOrConfig)) {
argumentNotNull(builder, "builder");
this._builders[nameOrConfig] = builder;
} else {
each(nameOrConfig, (v, k) => this.register(k, v));
}
return this;
}
cin
added provided and configure methods to the fluent container configuration, added applyConfig method to the container
r142 configure(config: FluentRegistrations<Y, S>): ContainerConfiguration<S> {
return this.register(config);
}
cin
tests
r136 apply<SC extends object>(target: Container<SC>, ct = Cancellation.none) {
cin
Completely removed IoC annotations...
r135
let pending = 1;
cin
tests
r136 const _t2 = target as unknown as Container<SC & S>;
return new Promise<Container<SC & S>>((resolve, reject) => {
cin
Completely removed IoC annotations...
r135 function guard(v: void | Promise<void>) {
if (isPromise(v))
v.catch(reject);
}
function complete() {
if (!--pending)
cin
tests
r136 resolve(_t2);
cin
Completely removed IoC annotations...
r135 }
each(this._builders, (v, k) => {
pending++;
cin
tests
r136 const d = new DescriptorBuilder<SC & S, any>(_t2,
cin
Completely removed IoC annotations...
r135 result => {
cin
tests
r136 _t2.register(k, result);
cin
Completely removed IoC annotations...
r135 complete();
},
reject
);
try {
guard(v(d, ct));
} catch (e) {
reject(e);
}
});
complete();
});
}
}