• Stars
    star
    164
  • Rank 230,032 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 6 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

More Repositories

1

midway

🍔 A Node.js Serverless Framework for front-end/full-stack developers. Build the application for next decade. Works on AWS, Alibaba Cloud, Tencent Cloud and traditional VM/Container. Super easy integrate with React and Vue. 🌈
TypeScript
7,125
star
2

pandora

A Manageable, Measurable and Traceable Node.js Application Manager represented by Alibaba powered by TypeScript
TypeScript
3,084
star
3

hooks

"Zero" Api / Type Safe / Fullstack Kit / Powerful Backend
TypeScript
690
star
4

midway-faas

🔱 A simple and lightweight serverless framework
TypeScript
390
star
5

midway-examples

show midway examples
JavaScript
147
star
6

subway-station

Node.js 地下铁分享资料汇总
115
star
7

pandora-dashboard

A local GUI Dashboard for Pandora.js
JavaScript
52
star
8

sandbox

Sandbox is a Node.js application monitoring platform, which allows the application to be deployed in its own environment, combined with the data source to generate a comprehensive application report.
TypeScript
50
star
9

midway-serverless-examples

TypeScript
36
star
10

midway-boilerplate

midway 系列脚手架仓库
TypeScript
24
star
11

cli

midway cli, provide local develop, test, and deploy functions through the two commands 'mw' or 'midway-bin'.
TypeScript
20
star
12

light-generator

a light generator for generate a boilerplate
TypeScript
15
star
13

sandbox-docker

一份基于 Docker Compose 的 Sandbox 部署配置
TypeScript
14
star
14

mwts

☂️ TypeScript style guide, formatter, and linter.
TypeScript
10
star
15

module-hook

TypeScript
9
star
16

midway-component

midway components
TypeScript
9
star
17

pgo

PGO(Profile Guided Optimization),是一种根据运行时 Profiling Data 来进行优化的技术。
TypeScript
7
star
18

metrics-common

A basic metrics implementation package for data aggregation computing in different scenarios.
TypeScript
6
star
19

midwayjs.github.io

midwayjs site
JavaScript
5
star
20

luckyeye

TypeScript
4
star
21

mwcc

🏜 MidwayJS Compiler Collection
TypeScript
4
star
22

pandora-reporter-open-falcon

pandora metrics reporter for open-falcon
TypeScript
4
star
23

midway-locate

locate your midway or midway-* project
TypeScript
3
star
24

logger

midway logger
TypeScript
3
star
25

event-bus

TypeScript
3
star
26

perf-bot

JavaScript
3
star
27

bundle-helper

midway bundle helper
TypeScript
3
star
28

lb

Go
3
star
29

pandora-example

Pandora.js examples
JavaScript
2
star
30

midway-upgrade

Upgrade midway to the latest version with 1-click
TypeScript
2
star
31

pandora-hook

Deprecated and move to pandora package
JavaScript
2
star
32

pandora-component-sandbox-log-hub-reporter

Pandora.js Component Sandbox Log Hub Reporter
TypeScript
2
star
33

umi-plugin-faas

JavaScript
2
star
34

dorapan

A mirror client sdk for Pandora.js
JavaScript
1
star
35

debugger

Currency Debug
TypeScript
1
star
36

midway-demo-lib

Some dependencies set for midway demo
1
star
37

jsdom-service-worker

Service worker global environment in Node.js
JavaScript
1
star
38

vue-cli-plugin-faas

Vue CLI Plugin For Midway FaaS
JavaScript
1
star
39

midway-code-mod

midway code operation
TypeScript
1
star
40

midway-next-site

TypeScript
1
star
41

vue-cli-plugin-midway-hooks

Provide midway hooks dev pack options to vue-cli
TypeScript
1
star
42

grpc-helper

TypeScript
1
star
43

glob

TypeScript
1
star
44

egg-ts-helper

JavaScript
1
star
45

mwtsc

it's a tsc wrapper
JavaScript
1
star