New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@benstack/inject

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@benstack/inject

Lightweight DI for Javascript

latest
npmnpm
Version
0.0.1
Version published
Maintainers
0
Created
Source

Inject

Inject

Lightweight Javascript DI Container

Inject is a lightweight dependency injection container for JS & TS

Install

pnpm install @benstack/inject

Usage

abstract class Globals {
	// ...
}

class MyGlobals extends Globals {
	// ...
}

const env = new InjectionKey<string>;

class MyClass {
	env = inject(env)
	globals = inject(Globals)
}

const container = new Container;
container.registerSingleton(Globals, MyGlobals)
container.registerTransient(MyClass);
container.registerValue(env, "development")

const myclass = container.resolve(MyClass)

assertEquals(myclass.env, "development") // true
assert(myclass.globals instanceof Globals) // true

License

Made with 💛

Published under MIT License.

FAQs

Package last updated on 29 Jun 2024

Did you know?

Socket

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.

Install

Related posts