# @jdl2/ioc

> This is ioc documentation

Latest version **2.0.0-alpha.30** (published 2018-09-27) · 0 weekly downloads

## Install

```sh
npm install @jdl2/ioc
pnpm add @jdl2/ioc
yarn add @jdl2/ioc
bun add @jdl2/ioc
```

## 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 | 2.0.0-alpha.30 |
| Published | 2018-09-27 |
| First published | 2018-09-27 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 1.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | kzantow |

## Links

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

## Dependencies (1)

- [@jdl2/log](https://npm.io/package/@jdl2/log.md) ^2.0.0-alpha.30

## Recent versions

- 2.0.0-alpha.30 (latest) — 2018-09-27

## README

# ioc

This is ioc documentation

If you want to have control over how instances are created,
it's possible to implement and register a provider. For example.
to automatically create logger instances with the name of a class
when `@inject Logger log`, you would do something like this:

```typescript
import { createLogger, Logger } from '@jdl2/log';
import { KeyMap } from '@jdl2/log';
import { Injector } from '@jdl2/ioc';

export function configure(injector: Injector) {
    const loggerInstances = new KeyMap();
    function LoggerProvider(i: Injector, obj: object): Logger {
        return loggerInstances.getOrCreate(obj.constructor, () => createLogger(obj.constructor.name));
    }
    injector.bind(Logger).toProvider(LoggerProvider);
}
```

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