FactoryServiceDescriptor.ts
23 lines
| 730 B
| video/mp2t
|
TypeScriptLexer
|
|
r49 | import { ServiceDescriptor, ServiceDescriptorParams } from "./ServiceDescriptor"; | ||
| import { Factory } from "../interfaces"; | ||||
| import { argumentNotNull, oid } from "../safe"; | ||||
| import { ActivationType } from "./interfaces"; | ||||
| export interface FactoryServiceDescriptorParams extends ServiceDescriptorParams { | ||||
| factory: Factory; | ||||
| } | ||||
| export class FactoryServiceDescriptor extends ServiceDescriptor { | ||||
| constructor(opts: FactoryServiceDescriptorParams) { | ||||
| super(opts); | ||||
| argumentNotNull(opts && opts.factory, "opts.factory"); | ||||
| // bind to null | ||||
| this._factory = () => opts.factory(); | ||||
| if (opts.activation === ActivationType.Singleton) { | ||||
| this._cacheId = oid(opts.factory); | ||||
| } | ||||
| } | ||||
| } | ||||
