# dependency-inject

> > [Live Demo](https://jsfiddle.net/yp90Lep9/15/)

Latest version **1.1.6** (published 2018-02-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install dependency-inject
pnpm add dependency-inject
yarn add dependency-inject
bun add dependency-inject
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.6 |
| Published | 2018-02-14 |
| First published | 2017-02-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 63.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Maintainers | ascoders |

## Links

- npm: https://www.npmjs.com/package/dependency-inject
- Repository: https://github.com/ascoders/dependency-inject
- Homepage: https://github.com/ascoders/dependency-inject#readme
- Issues: https://github.com/ascoders/dependency-inject/issues
- npm.io page: https://npm.io/package/dependency-inject

## Recent versions

- 1.1.6 (latest) — 2018-02-14
- 1.1.5 — 2018-02-02
- 1.1.4 — 2017-12-03
- 1.1.3 — 2017-12-03
- 1.1.2 — 2017-11-27
- 1.1.1 — 2017-11-06
- 1.1.0 — 2017-09-07
- 1.0.19 — 2017-09-02
- 1.0.18 — 2017-07-10
- 1.0.17 — 2017-06-19
- 1.0.16 — 2017-06-19
- 1.0.15 — 2017-06-17
- 1.0.14 — 2017-06-17
- 1.0.13 — 2017-06-17
- 1.0.12 — 2017-06-17
- … 12 more at https://npm.io/package/dependency-inject/versions

## README

# DependencyInject

> [Live Demo](https://jsfiddle.net/yp90Lep9/15/)

```typescript
import { Container, inject } from 'dependency-inject'

class Store {
    num = 1
}

class Action {
    @inject(Store)
    private store: Store

    setNum(num: number) {
        this.store.num = num
    }
}

// init store
const container = new Container()
container.set(Store, new Store())
container.set(Action, new Action())

// get data with injected
const store = container.get(Store)
const action = container.get(Action)

action.setNum(2)
console.log(store.num) // 2
```

# Simple useage by injectFactory

```typescript
import { injectFactory } from 'dependency-inject'
class Store {
    num = 1
}

class Action {
    @inject(Store)
    private store: Store

    setNum(num: number) {
        this.store.num = num
    }
}

const stores = injectFactory({Store, Action})
// stores.Store.num === 1
// stores.Action.setNum
```

## nested object

```typescript
import { injectFactory } from 'dependency-inject'
class Store {
    num = 1
}

class Action {
    @inject(Store)
    private store: Store

    setNum(num: number) {
        this.store.num = num
    }
}

const stores = injectFactory({
    groupA: Store,
    groupB: {
        groupC: Action
    }
})
```

---
_Source: https://npm.io/package/dependency-inject · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
