
Security News
Insecure Agents Podcast: Certified Patches, Supply Chain Security, and AI Agents
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.
singleton-injection
Advanced tools
A simple way to manage singletons
This provides a way to create Singleton Container to store Singleton instances
// container.ts
import { SingletonContainer } from "singleton-injection";
// Define your singletons
const singletonMap = {
shape: () => new Circle() as Shape,
otherShape: () => new Square() as Shape
};
// Create Singleton container
export const container = new SingletonContainer(singletonMap);
// app.ts
// Get instance in your app with
import { container } from "./container";
// now you can get same instance of shape anywhere in your code
const shape = container.resolve("shape");
// you will get TS suggestions for parameter of `resolve`, so no need to worry about spelling mistakes
// Destroy container instances
container.destroy();
// after destroy, container.resolve will create and return new instances
container.mock({
shape: () => new MockedSquare() as Shape
});
// With above all `container.resolve("shape")` calls will return this mocked shape
// Note: mocked instances are not singletons, it will create instance everytime
// To restore mock, you can use same method with empty object, this will restore the original container
container.mock({});
FAQs
A simple way to manage singletons in TypeScript projects
We found that singleton-injection demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.

Security News
The planned feature introduces a review step before releases go live, following the Shai-Hulud attacks and a rocky migration off classic tokens that disrupted maintainer workflows.