# ioc-di-ts

> A lightweight, extensible dependency injection container for TypeScript/JavaScript.

Latest version **1.0.5** (published 2020-06-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install ioc-di-ts
pnpm add ioc-di-ts
yarn add ioc-di-ts
bun add ioc-di-ts
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2020-06-07 |
| First published | 2020-06-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 204.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | YISH |
| Maintainers | mokeyish |

## Links

- npm: https://www.npmjs.com/package/ioc-di-ts
- Repository: https://github.com/mokeyish/dependency-injection.ts
- Homepage: https://github.com/mokeyish/dependency-injection.ts#readme
- Issues: https://github.com/mokeyish/dependency-injection.ts/issues
- npm.io page: https://npm.io/package/ioc-di-ts

## Dependencies (2)

- [ioc-di-ts](https://npm.io/package/ioc-di-ts.md) ^1.0.3
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13

## Recent versions

- 1.0.5 (latest) — 2020-06-07
- 1.0.3 — 2020-06-07
- 1.0.2 — 2020-06-07
- 1.0.1 — 2020-06-07
- 1.0.0 — 2020-06-05

## README

# Dependency Injection

> A lightweight, extensible dependency injection container for TypeScript/JavaScript.

1. Install

`yarn add ioc-di-ts`


2. Example

```ts

import { Injectable, Injector, INJECTOR_SCOPE } from 'ioc-di-ts';
@Injectable()
class Bar {
    name = 'abc';
}

@Injectable({ providedIn: 'root'})
class Foo {
    constructor(public bar: Bar) {
    }
}

const injector = Injector.resolveAndCreate([
        { provide: Bar },
        { provide: INJECTOR_SCOPE, useValue: 'root'}
        // { provide: Foo }
    ]
);

const foo = injector.get(Foo);
const bar = injector.get(Bar);
expect(foo.bar).toEqual(bar);
expect(foo.bar.name).toEqual('abc');

@Injectable({ providedIn: 'root'})
class Foo1 {
    constructor(public bar: Bar) {
    }
}

const injectorChild = Injector.resolveAndCreate( [
    { provide: Foo1, }
], injector)

const foo1 = injectorChild.get(Foo1);
expect(foo1.bar).toEqual(bar);
expect(foo1.bar.name).toEqual('abc');
```

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