# node-dinjector

> Node-DInjector, design to be a simple and practical dependency injection library.

Latest version **1.0.46** (published 2018-02-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install node-dinjector
pnpm add node-dinjector
yarn add node-dinjector
bun add node-dinjector
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.46 |
| Published | 2018-02-06 |
| First published | 2017-10-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jeton Shehu |
| Maintainers | jshehu |
| Keywords | dependency, injection, dependency, di |

## Links

- npm: https://www.npmjs.com/package/node-dinjector
- Repository: https://github.com/jshehu/node-dinjector
- Homepage: https://github.com/jshehu/node-dinjector#readme
- Issues: https://github.com/jshehu/node-dinjector/issues
- npm.io page: https://npm.io/package/node-dinjector

## Dependencies (1)

- [get-func-args](https://npm.io/package/get-func-args.md) ^1.0.4

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.0.46 (latest) — 2018-02-06
- 1.0.45 — 2017-12-17
- 1.0.44 — 2017-12-06
- 1.0.43 — 2017-11-02
- 1.0.42 — 2017-10-28
- 1.0.41 — 2017-10-28
- 1.0.4 — 2017-10-28
- 1.0.31 — 2017-10-28
- 1.0.22 — 2017-10-28
- 1.0.3 — 2017-10-28
- 1.0.21 — 2017-10-28
- 1.0.11 — 2017-10-28
- 1.0.2 — 2017-10-28
- 1.0.1 — 2017-10-28
- 1.0.0 — 2017-10-28

## README

## Node Dependency Injection
- **API**
  - **Injector**
    - [`class([store])`](#injector-class)
    - [`injector.setStore(store)`](#injector-setStore)
    - [`injector.getStore()`](#injector-getStore)
    - [`injector.resolve(func, [thisArg, staticArgs])`](#injector-resolve)
  - **Store**
    - [`class([dep, asyncDep])`](#store-class)
    - [`store.set(name, value):`](#store-set)
    - [`store.get(name)`](#store-get)
    - [`store.has(name)`](#store-has)
    - [`store.declare(name):`](#store-declare)
    - [`store.resolve(name, value)`](#store-resolve)
    - [`store.list()`](#store-list)
    - [`store.asyncList()`](#store-asyncList)
  - **Helper**
    - [`class.arguments([func])`](#helper-arguments)
    - [`class.functions(obj)`](#helper-functions)
    - [`class.mapFunctions(obj)`](#helper-mapFunctions)

### Installation
```js
npm i -S node-dinjector
```

### Including library in your project
```js
const DInjector = require('node-dinjector');
const DInjectorStore = DInjector.Store;
const DInjectorHelper = DInjector.Helper;
```

### Example
```js
const DInjector = require('../DInjector');
const DInjectorStore = DInjector.Store;
const DInjectorHelper = DInjector.Helper;

const injector = new DInjector();
injector.getStore().set('a', 123); // set di

class Controller {
  test(a, b) {
    console.log(a, b);
  },
  test(c, a, b) {
    console.log(c, a, b);
  }
}
const c = new Controller();
// replace c functions with resolved functions using injector
DInjectorHelper.mapFunctions(c, func => injector.resolve(func, c));
// call test function with b parameter
c.test(5);
// call test2 function with c and b parameters
c.test2(1, 2);
```

*Will get updated soon*

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