# @rootsher/di-resolver

> Typed Dependency Injection Container

Latest version **0.1.0** (published 2020-06-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install @rootsher/di-resolver
pnpm add @rootsher/di-resolver
yarn add @rootsher/di-resolver
bun add @rootsher/di-resolver
```

## 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.1.0 |
| Published | 2020-06-28 |
| First published | 2020-06-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Konrad Kowalski |
| Maintainers | rootsher |
| Keywords | typed, di, dependency, injection, container, resolver |

## Links

- npm: https://www.npmjs.com/package/@rootsher/di-resolver
- Repository: https://github.com/rootsher/di-resolver
- Homepage: https://github.com/rootsher/di-resolver#readme
- Issues: https://github.com/rootsher/di-resolver/issues
- npm.io page: https://npm.io/package/@rootsher/di-resolver

## 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.1.0 (latest) — 2020-06-28

## README

# @rootsher/di-resolver

## installation

```sh
$ npm install @rootsher/di-resolver
```

## example usage

* define class A:

```ts
// [A]
class A {
    private value: number = 1;

    method(): number {
        return this.value;
    }
}
```

* define class B:

```ts
// [B, { deps: [A] }]
class B {
    private a: A;

    constructor(a: A) {
        this.a = a;
    }

    callAMethod(): number {
        return this.a.method();
    }
}
```

* define class C:

```ts
// [C, { deps: [B, A] }]
class C {
    public value: number = 2;

    constructor(private b: B, a: A) {}

    method({ value }: { value: number }) {
        this.value = value;
    }
}
```

* create dependency injection container definitions:

```ts
import { Resolver } from 'typed-di-container';

const resolver = new Resolver([
    [A],
    [
        B,
        { deps: [A] }
    ],
    [
        C,
        {
            deps: [B, A],
            calls: [
                (c: C) => c.method({ value: 15 })
            ]
        }
    ]
]);
```

* simple access to instances (`resolver.get([class])`):

```ts
console.log(resolver.get(B).callAMethod()); // 1
console.log(resolver.get(C).value); // 15
```

## IDE support

```ts
// IDE will help with types ("value" property, "method" method etc.)
"resolver.get(C).[value/method]"
```

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