Skip to content

b3nten/inject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published