Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
I

injection-js

> 编程语言
Open source

Dependency injection library for JavaScript and TypeScript in 5.1K. It is an extraction of the Angular's ReflectiveInjector which means that it's well designed,

1.4K stars0 likes2 views
WebsiteGitHub

About

Dependency injection library for JavaScript and TypeScript in 5.1K. It is an extraction of the Angular's ReflectiveInjector which means that it's well designed,

Dependency Injection

Dependency injection library for JavaScript and TypeScript in 5.2K. It is an extraction of the Angular's dependency injection which means that it's feature complete, fast, reliable and well tested.

Why not Angular version 5 and above?

Angular version 5 deprecated the ReflectiveInjector API and introduced StaticInjector. In short, the dependency injection in the newest versions of Angular will happen entirely compile-time so reflection will not be necessary.

However, if you want to use dependency injection in your Node.js, Vue, React, Vanilla JS, TypeScript, etc. application you won't be able to take advantage of StaticInjector the way that Angular will because your application won't be compatible with Angular compiler.

This means that if you need dependency injection outside of Angular @angular/core is not an option. In such case, use injection-js for fast, small, reliable, high-quality, well designed and well tested solution.

How to use?

bash
$ npm i injection-js
# OR
$ yarn add injection-js

Note:

For ES5 Class syntax and TypeScript you need a polyfill for the Reflect API. You can use:

  • reflection (only 3kb )
  • reflect-metadata
  • core-js (core-js/es7/reflect)

Also for TypeScript you will need to enable experimentalDecorators and emitDecoratorMetadata flags within your tsconfig.json

TypeScript

Using the latest inject function:

typescript
import { inject, ReflectiveInjector } from 'injection-js';

class Http {}

class Service {
  http = inject(Http);
}

const injector = ReflectiveInjector.resolveAndCreate([Http, Service]);

console.log(injector.get(Service) instanceof Service);
console.log(injector.get(Service).http instanceof Http);

Using @Injectable and reflect-metadata:

…

ES6

javascript
const { Inject, ReflectiveInjector } = require('injection-js');

class Http {}

class Service {
  static get parameters() {
    return [new Inject(Http)];
  }

  constructor(http) {
    this.http = http;
  }
}

const injector = ReflectiveInjector.resolveAndCreate([Http, Service]);

console.log(injector.get(Service) instanceof Service);

ES5

javascript
require('reflect-metadata');
var di = require('injection-js');

var Http = di.Class({
  constructor: function() {},
});

var Service = di.Class({
  constructor: [
    Http,
    function(http) {
      this.http = http;
    },
  ],
});

var injector = di.ReflectiveInjector.resolveAndCreate([Http, Service]);

console.log(injector.get(Service) instanceof Service);

API

For full documentation check Angular DI docs:

  • Dependency Injection
  • Dependency Injection in action
  • Dependency Injection without Typescript

Ecosystem

This is a list of libraries that are using injection-js. If you have a suggestion on what to add, please don't hesitate to submit a PR.

Libraries

  • ng-packagr Transpile your libraries to Angular Package Format. Part of the official Angular CLI.
  • @martin_hotell/axios-http Injectable axios HttpClient wrapper for browser and node
  • @martin_hotell/rea-di Dependency injection for React done right. Hierarchical injection on both component and service layer powered by injection-js (Angular DI framework)
  • rxstack RxStack is a realtime object-oriented framework which helps you build a micro service web applications on top of other frameworks like express and socketio by adding an abstraction layer.
  • ServeRX-ts Experimental Node.js HTTP framework using RxJS, built with TypeScript and optimized for serverless deployments. Features declarative routes and dependency injection powered by injection-js.

License

MIT

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptdecoratorsdependency-injectionjavascriptnode

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言