Factory
Callable
Type parameters
- T
Parameters
type: string | Constructable<T>
The type of class that the factory creates.
optionaloptions: { metadata?: {} }
Allows registering multiple factories for the same class that differ by metadata.
optionalmetadata: {}
Returns (constructor: { create: (...args: unknown[]) => Promise<T> }) => void
The decorated class.
Parameters
constructor: { create: (...args: unknown[]) => Promise<T> }
create: (...args: unknown[]) => Promise<T>
Returns void
A
@Factoryis a class decorator to be placed on top of a class that represents a factory. A factory is responsible for creating instances of a class - Octo resolves every service through one rather than callingnew, which is what lets you swap an internal implementation for your own.The same class may have several factories, told apart by their metadata. The factory registered without metadata is the default.
Decorators
A factory that produces a singleton must
awaitits own dependencies before the instance check. Awaiting inside the check is a race - concurrent callers each pass the check while suspended, and each gets a different instance.