FactoryServiceDescriptor.ts
22 lines
| 802 B
| video/mp2t
|
TypeScriptLexer
|
|
r49 | import { ServiceDescriptor, ServiceDescriptorParams } from "./ServiceDescriptor"; | ||
| import { argumentNotNull, oid } from "../safe"; | ||||
| import { ActivationType } from "./interfaces"; | ||||
|
|
r115 | export interface FactoryServiceDescriptorParams<S, T, P extends any[]> extends ServiceDescriptorParams<S, T, P> { | ||
| factory: (...args: P) => T; | ||||
|
|
r49 | } | ||
|
|
r115 | export class FactoryServiceDescriptor<S, T, P extends any[]> extends ServiceDescriptor<S, T, P> { | ||
| constructor(opts: FactoryServiceDescriptorParams<S, T, P>) { | ||||
|
|
r49 | super(opts); | ||
| argumentNotNull(opts && opts.factory, "opts.factory"); | ||||
| // bind to null | ||||
|
|
r115 | this._factory = (...args) => opts.factory.apply(null, args as any); | ||
|
|
r49 | |||
| if (opts.activation === ActivationType.Singleton) { | ||||
| this._cacheId = oid(opts.factory); | ||||
| } | ||||
| } | ||||
| } | ||||
