Singleton Injection
A simple way to manage singletons
This provides a way to create Singleton Container to store Singleton instances
Usage
import { SingletonContainer } from "singleton-injection";
const singletonMap = {
shape: () => new Circle() as Shape,
otherShape: () => new Square() as Shape
};
export const container = new SingletonContainer(singletonMap);
import { container } from "./container";
const shape = container.resolve("shape");
container.destroy();
Mocking in Tests
container.mock({
shape: () => new MockedSquare() as Shape
});
container.mock({});