# dic-ioc

> A simple injector of dependencies container

Latest version **0.1.1** (published 2021-02-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install dic-ioc
pnpm add dic-ioc
yarn add dic-ioc
bun add dic-ioc
```

## Health

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

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

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2021-02-09 |
| First published | 2021-02-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 10.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Valentin Valverde |
| Maintainers | valen-developer |

## Links

- npm: https://www.npmjs.com/package/dic-ioc
- npm.io page: https://npm.io/package/dic-ioc

## Recent versions

- 0.1.1 (latest) — 2021-02-09
- 0.1.0 — 2021-02-09
- 0.0.1 — 2021-02-09

## README

# IOC [![NPM Module](https://img.shields.io/badge/npm-0.1.1-red)](https://www.npmjs.com/package/dic-ioc)

A simple dependencies injector container.

## Install

(alpha version. Don´t use in production, I´m not responsible for that)

```
$ npm i dic-ioc
```

# Usage

To use this package, I recommend you define different files where you set your dependencies:
../user-ioc.ts

```
export default userIOCGenerator( container: IOC ){

    //First set Services without dependencies
    container.setService( 'UserRepository', ()=> new UserRepository());

    //Set Services with dependencies (already set)
    container.setService( 'UserCreator', (c:IOC)=> new UserCreator( c.get( 'UserRepository')));

}
```

Then, when you have created all of your dependencies files:
../container-ioc.ts

```
import { IOC } from 'dic-ioc';

import UserIOC from "./user-ioc.ts";


export const getContainer = ()=>{

    //Build container
    const container = new IOC();

    //Set user dependencies
    UserIOC(container);

    return container;

}
```

Finally, use container where you need:
../userCreatorController.ts

```
import { getContainer } from "./container-ioc";

export class UserCreatorController implement Controller{

    public run(req, res){

        const container: IOC = getContainer();

        const userCreator: UserCreator = container.get('UserCreator');
        userCreator.save();

        ...

        res.status(201);

    }

}
```

## License

dic-ioc is under [MIT](https://en.wikipedia.org/wiki/MIT_License) License

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