# another-di

> Yeah it's a di for javascript...

Latest version **3.0.0** (published 2018-05-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install another-di
pnpm add another-di
yarn add another-di
bun add another-di
```

## 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 | 3.0.0 |
| Published | 2018-05-31 |
| First published | 2015-10-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dominic Smith |
| Maintainers | loke |
| Keywords | di |

## Links

- npm: https://www.npmjs.com/package/another-di
- npm.io page: https://npm.io/package/another-di

## Dependencies (1)

- [prom-client](https://npm.io/package/prom-client.md) ^11.0.0

## 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

- 3.0.0 (latest) — 2018-05-31
- 2.0.0 — 2018-05-31
- 1.0.0 — 2015-10-28

## README

# another-di

This is another dependency injector, because there aren't enough.

## Usage

```js
// lib/hello-message.js

module.exports = function () {
  return 'hello world!';
}

// lib/boomer.js

module.exports = function ({helloMessage}) {
  return {
    boom: function () {
      console.log(helloMessage);
    }
  }
}

// lib/index.js

var di = require('another-di');

module.exports = di.create()
.singleton('helloMessage', require('./hello-message')) // dashes converted to camelcase
.singleton('boomer', require('./boomer'))

// main.js

var lib = require('./lib');

lib.run(function ({boomer}) {
  boomer.boom(); // logs out 'hello world'
});


// test.js

var lib = require('./lib');
var boomer;

beforeEach(function () {
  testContainer = lib.clone();
  testContainer.singleton('helloMessage', function () {
    return 'hello from test land';
  });

  testContainer.run(function ({_boomer}) { // underscore is striped before dependency lookup
    boomer = _boomer;
  })
})

it('should boom!', () => {
  boomer.boom(); // logs 'hello from test land'
});

```

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