Documents injecute 1.x · Migrating from 0.x
Skip to content

Interface: SingletonFactoryOptions<D, F, R> ​

Defined in: src/types.ts:183

Options of addSingleton(key, factory, options): SingletonOptions for the instance type factory produces. The instance type is worked out only when an options object is passed, which keeps registration chains cheap to typecheck.

Example ​

ts
app.addSingleton('pool', createPool, {
  dependencies: ['config'],
  dispose: (pool) => pool.end(), // pool: Awaited<ReturnType<typeof createPool>>
});

Extends ​

Type Parameters ​

D ​

D

F ​

F

R ​

R extends boolean = boolean

Properties ​

dependencies? ​

optional dependencies?: D

Defined in: src/types.ts:148

Dependency keys, passed to the factory in the same order.

Inherited from ​

RegistrationOptions.dependencies


dispose? ​

optional dispose?: DisposeOption<Awaited<Produced<F>>>

Defined in: src/types.ts:189

How dispose() releases the instance. Default: auto-detect [Symbol.asyncDispose] / [Symbol.dispose].


replace? ​

optional replace?: R

Defined in: src/types.ts:161

Replace an existing registration of this key: one in the same container, or a parent's one in a fork (required there too). With replace: true the service's type becomes the new one (see Registered).

In a plain fork the replacement applies to services resolved in the fork: services registered in a parent keep the parent's instance. In an isolated fork it applies to every service resolved through the fork.

There must be something to replace: replace: true for a key that no container has throws INJECUTE_NOTHING_TO_REPLACE.

Inherited from ​

RegistrationOptions.replace

Released under the MIT License.