# nodic

> Service Container for browser an node

Latest version **0.4.0** (published 2018-06-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install nodic
pnpm add nodic
yarn add nodic
bun add nodic
```

## 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.4.0 |
| Published | 2018-06-28 |
| First published | 2017-03-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 6.10.0 |
| Dependencies | 0 |
| Unpacked size | 65.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ivan Zakharchenko |
| Maintainers | 3axap4ehko |
| Keywords | di, dependency, injection, service, container |

## Links

- npm: https://www.npmjs.com/package/nodic
- Repository: https://github.com/3axap4eHko/nodic
- Homepage: https://github.com/3axap4eHko/nodic#readme
- Issues: https://github.com/3axap4eHko/nodic/issues
- npm.io page: https://npm.io/package/nodic

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

- 0.4.0 (latest) — 2018-06-28
- 0.2.0 — 2017-03-09
- 0.1.0 — 2017-03-08

## README

# NoDIC

0-dependency Service Container for browser an node

## Install
 $ npm install nodic
 
## Reference

### Service

`service` is an object contains following properties:
 - name     - service name
 - classOf  - service class
 - factory  - service factory function
 - args     - array of service constructor or factory arguments
 - tags     - service tags (array of strings)
 - shared   - is the service shared or every time should be instantiated
 - instance - instance of service target

---
### DI

```
class DI {
    has(name)
    get(name, args)
    set(name, instance, options) {
    injectService(target, serviceName)
    register(name, options)
    find(callback)
    findFirst(callback)
    resolveService(service, args)
    resolveArg(arg)
    services
}
```

`createService(name, options)` - creates service from provided arguments
``` javascript
var service = DI.createService('myService', {classOf: Array, args: [[1,2,3,4,5]], tags: ['array']});
```
`injectService(target, serviceName)` - proxify `target` properties starts from `$` sign to service getter
```
var target = {$myService: null};
DI.injectService(target, 'myService');
console.log(target.$myService); // [1,2,3,4,5]
```
`has (name)` - returns true if service exists
`register (name, options)` - register new service with `name` and `options`
`set (name, instance, options)` - set service with name `name` provided `instance` and `options`
`get (name, args)` - returns service instance by `name` if service does not exists create with arguments `args`
`find(callback)` - returns all services where `callback` returns true
`findFirst (callback)` - return first service on `callback` returns true
`resolveService(service, args)` - resolves service `service` with arguments `args` and returns `instance`
`resolveArg (arg)` - returns service instance with name `arg` or `arg`
`services` - list of services names


## Example
``` javascript
import createService, { DI } from 'nodic';

const di = new DI();
const serviceDate = createService('date', { factory: () => new Date(), tags: ['date'] });
const serviceCurDate = createService('currentDate', { factory: () => new Date(), shared: false, tags: ['date'] });

di.register(serviceDate);
di.register(serviceCurDate);

console.log(di.get('date') === di.get('date')); // true
console.log(di.get('currentDate') === di.get('currentDate')); // false
```

## License
[The MIT License](http://opensource.org/licenses/MIT)
Copyright (c) 2015-present Ivan Zakharchenko

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