# kontainer-di-config

> Setup kontainer-di through configuration

Latest version **0.0.6** (published 2015-11-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install kontainer-di-config
pnpm add kontainer-di-config
yarn add kontainer-di-config
bun add kontainer-di-config
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2015-11-03 |
| First published | 2015-10-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Benoit Sagols |
| Maintainers | eightyfive |

## Links

- npm: https://www.npmjs.com/package/kontainer-di-config
- Repository: https://github.com/eightyfive/kontainer-di-config
- Issues: https://github.com/eightyfive/kontainer-di-config/issues
- npm.io page: https://npm.io/package/kontainer-di-config

## Recent versions

- 0.0.6 (latest) — 2015-11-03
- 0.0.5 — 2015-11-02
- 0.0.4 — 2015-10-30
- 0.0.3 — 2015-10-30
- 0.0.2 — 2015-10-30
- 0.0.1 — 2015-10-30

## README

# kontainer-di-config
Setup [kontainer-di](https://github.com/redradix/kontainer) through configuration

## Installation

```js
$ npm install kontainer-di-config --save
```

## Usage

```js
var di = require('kontainer-di-config')(require('kontainer-di'), diConfig, dirname);
```

### Sample `diConfig` object (required)

```js
{
  "env": "prod", /* [1] */
  "isDev": false, /* [2] */
  "roles": ["admin", "user"], /* [3] */
  "knex.config": {"client": "pg", ... }, /* [4] */
  
  "config.path": "./config/prod.json", /* [5] */
  "config": "(./config/prod.json)", /* [6] */

  "knex": {"(knex)": ["knex.config"]}, /* [7] */
  "bookshelf": {"(bookshelf)": ["knex"]},

  "user.model": {"(./models/user)": ["bookshelf", "dep2", "dep3", ...]}, /* [8] */
  "user.service": {"(./services/user)": ["user.model"]},
  ...
}
```

1. You can register a `string` directly from the config
2. Or a `boolean`...
3. Or an `Array`.
4. And of course an `object`!
5. Here, this won't load/require the `json` file
6. Here yes! (because it's wrapped between paranthesis, this is the way to `require` something)
7. You can even `require` Node modules, as long as they follow the factory pattern
8. Etc...

### `dirname` option (required)

All "requirable" relative paths (between paranthesis) given in config, are resolved from the `dirname` option. Meaning you may need to adjust the `dirname` option regarding from where you want to declare you dependencies in the config file/object:

```js
var config = {
  "user": {"./src/models/user": ["bookshelf"]}
};
var di = konfigure(kontainer, config, __dirname);

// -- OR --

var config = {
  "user": {"./models/user": ["bookshelf"]}
};
var di = konfigure(kontainer, config, path.resolve(__dirname, 'src'));
```

You can also browse the [source code](https://github.com/eightyfive/kontainer-di-config/blob/master/index.js) to get a better idea of this.


## Example

```js
var kontainer = require('kontainer-di');
var konfigure = require('kontainer-di-config');
var config    = require('./config/di.json');

var di = konfigure(kontainer, config, __dirname);
var userService;

userService = di.get('user.service');
userService.findAll().then( ... );

// ...
```

See the [example](https://github.com/eightyfive/kontainer-di-config/tree/master/example) folder for the complete example.

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