injection
A New IoC Container For All Node.js Application
Last updated 5 years ago by czy88840616 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install injection 
SYNC missed versions from official npm registry.

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>('userService'); 
  const data = await userService.getUser(123);
  return data;
}

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

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

License

MIT

Current Tags

  • 1.8.4                                ...           beta (5 years ago)
  • 1.8.6                                ...           latest (5 years ago)
  • 1.7.6                                ...           next (5 years ago)

73 Versions

  • 1.8.6                                ...           5 years ago
  • 1.8.5                                ...           5 years ago
  • 1.8.4                                ...           5 years ago
  • 1.8.3                                ...           5 years ago
  • 1.8.2                                ...           5 years ago
  • 1.8.1                                ...           5 years ago
  • 1.8.0                                ...           5 years ago
  • 1.7.7                                ...           5 years ago
  • 1.7.6                                ...           5 years ago
  • 1.7.5-beta.1                                ...           5 years ago
  • 1.7.5-beta.0                                ...           5 years ago
  • 1.7.5                                ...           5 years ago
  • 1.7.4                                ...           5 years ago
  • 1.7.3                                ...           5 years ago
  • 1.7.2                                ...           5 years ago
  • 1.7.1                                ...           5 years ago
  • 1.7.0                                ...           5 years ago
  • 1.6.1                                ...           5 years ago
  • 1.6.0                                ...           5 years ago
  • 1.5.2                                ...           5 years ago
  • 1.5.1                                ...           5 years ago
  • 1.5.0                                ...           5 years ago
  • 1.5.0-beta.1                                ...           5 years ago
  • 1.4.2                                ...           6 years ago
  • 1.4.1                                ...           6 years ago
  • 1.4.0                                ...           6 years ago
  • 1.3.2                                ...           6 years ago
  • 1.3.1                                ...           6 years ago
  • 1.3.0                                ...           6 years ago
  • 1.2.0                                ...           6 years ago
  • 1.1.1                                ...           6 years ago
  • 1.1.0                                ...           6 years ago
  • 1.0.2                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
  • 0.7.0                                ...           6 years ago
  • 0.6.5                                ...           6 years ago
  • 0.6.4                                ...           6 years ago
  • 0.6.3                                ...           6 years ago
  • 0.6.2                                ...           6 years ago
  • 0.6.0                                ...           6 years ago
  • 0.5.0                                ...           6 years ago
  • 0.4.6                                ...           6 years ago
  • 0.4.5                                ...           6 years ago
  • 0.4.5-alpha.10                                ...           6 years ago
  • 0.4.5-alpha.8                                ...           6 years ago
  • 0.4.1                                ...           6 years ago
  • 0.3.8                                ...           6 years ago
  • 0.3.2                                ...           6 years ago
  • 0.3.1                                ...           6 years ago
  • 0.3.0                                ...           6 years ago
  • 0.2.10                                ...           6 years ago
  • 0.2.7                                ...           6 years ago
  • 0.2.4                                ...           6 years ago
  • 0.2.3                                ...           6 years ago
  • 0.2.2                                ...           6 years ago
  • 0.2.1                                ...           6 years ago
  • 0.2.0                                ...           6 years ago
  • 0.1.6                                ...           6 years ago
  • 0.2.0-alpha.1663751b                                ...           6 years ago
  • 0.1.5                                ...           6 years ago
  • 0.1.4                                ...           6 years ago
  • 0.1.3                                ...           6 years ago
  • 0.1.2                                ...           6 years ago
  • 0.1.1                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
  • 0.0.7                                ...           11 years ago
  • 0.0.6                                ...           11 years ago
  • 0.0.5                                ...           11 years ago
  • 0.0.4                                ...           11 years ago
  • 0.0.3                                ...           11 years ago
  • 0.0.2                                ...           11 years ago
  • 0.0.1                                ...           12 years ago
Maintainers (2)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (14)
Dev Dependencies (20)

© 2010 - cnpmjs.org x YWFE | Home | YWFE