Need help with injection?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

midwayjs
140 Stars 16 Forks MIT License 159 Commits 2 Opened issues

Description

Injection is a powerful inversion of control container that is widely used in the midway framework and brings good user experience.

Services available

!
?

Need anything else?

Contributors list

Injection

GitHub license GitHub tag Build Status Test Coverage Package Quality PRs Welcome

Injection is a powerful inversion of control container that is widely used in the midway framework and brings good user experience.

Installation

$ npm install injection reflect-metadata --save

Node.js >= 10.0.0 required.

Injection requires TypeScript >= 2.0 and the experimentalDecorators, emitDecoratorMetadata, types and lib compilation options in your tsconfig.json file.

{
  "compilerOptions": {
    "target": "ES2018",
    "module": "commonjs",
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "inlineSourceMap":true,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "stripInternal": true,
    "pretty": true,
    "declaration": true,
    "outDir": "dist",
    "lib": ["ES2018", "dom"]
  }
}

Getting Started

import {Container, provide, inject} from 'injection';

@provide('userModel') class UserModel {

}

@provide('userService') class UserService {

@inject() private userModel;

async getUser(uid) { // TODO return 'Alex'; } }

const container = new Container(); container.bind(UserService); container.bind(UserModel);

async function getData() { const userService = await container.getAsync('userService'); const data = await userService.getUser(123); return data; }

getData().then(console.log); // Alex

Document: https://midwayjs.org/injection/guide.html

License

MIT

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.