Singleton Decorator

The singleton pattern allows us to restrict a class's instantiation to a single instance during a program's lifecycle.

When using the @singleton() decorator to decorate a class, Injex will ensure you get the same instance of this class whenever you inject it into another module.


To use the @singleton() decorator, put it above an exported class.

import { define, singleton } from "@injex/core";
export class MyService {

Injex decorators can be used in any order.