# @typemon/ioc-container

> Inversion of Control Container

Latest version **1.1.1** (published 2019-02-21) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @typemon/ioc-container
pnpm add @typemon/ioc-container
yarn add @typemon/ioc-container
bun add @typemon/ioc-container
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2019-02-21 |
| First published | 2019-02-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 12.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Monster Space Network |
| Maintainers | monsterspace.network |
| Keywords | monster-space-network, typemon, ioc-container, inversion-of-control-container, ioc, inversion-of-control, di, dependency-injection, injection, injectable, inject, injection-token, inject-token |

## Links

- npm: https://www.npmjs.com/package/@typemon/ioc-container
- Repository: https://gitlab.com/monster-space-network/typemon/ioc
- npm.io page: https://npm.io/package/@typemon/ioc-container

## Dependencies (3)

- [inversify](https://npm.io/package/inversify.md) ^5.0.1
- [@typemon/types](https://npm.io/package/@typemon/types.md) ^2.0.1
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13

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

- 1.1.1 (latest) — 2019-02-21
- 1.1.0 — 2019-02-15
- 1.0.0 — 2019-02-14

## README

# IoC Container
> Inversion of Control Container

[![npm-version](https://img.shields.io/npm/v/@typemon/ioc-container.svg)](https://www.npmjs.com/package/@typemon/ioc-container)
[![npm-downloads](https://img.shields.io/npm/dt/@typemon/ioc-container.svg)](https://www.npmjs.com/package/@typemon/ioc-container)



### This package internally uses [`Inversify`](https://github.com/inversify/InversifyJS)



# Features
- Injection token
- Simple usage



# Getting Started

## Installation
```
$ npm install @typemon/ioc-container
```
```typescript
import {
    /* Container Class and Interfaces */
    Container, ReadonlyContainer, BindonlyContainer,

    /* Binding Syntaxes */
    BindingToSyntax,

    /* Injection-Token Class */
    InjectionToken,

    /* Decorators */
    Injectable, Inject, Optional,

    /* Types */
    Identifiable, Identifier
} from '@typemon/ioc-container';
```

## Usage
```typescript
const MonsterNameToken: InjectionToken<string> = new InjectionToken(Symbol.for('MonsterName'));
const MonsterName: () => ParameterDecorator = (): ParameterDecorator => Inject(MonsterNameToken);
const MonsterPackagesToken: InjectionToken<ReadonlyArray<string>> = new InjectionToken(Symbol.for('MonsterPackages'));
const MonsterPackages: () => ParameterDecorator = (): ParameterDecorator => Inject(MonsterPackagesToken);

@Injectable()
class MonsterService {
    public readonly packages: ReadonlyArray<string>;

    public constructor(
        @MonsterName() public readonly name: string,
        @MonsterPackages() @Optional() packages?: ReadonlyArray<string>
    ) {
        this.packages = packages || ['ioc-container'];
    }
}

@Injectable()
class Adventurer {
    public constructor(
        public readonly pet: MonsterService
    ) { }
}

const container: Container = new Container();

container.bind(MonsterNameToken).toConstantValue('Typemon');
container.bind(MonsterService).toSelf();
container.bind(Adventurer).toSelf();

const adventurer: Adventurer = container.resolve(Adventurer);

console.log(adventurer.pet.name, adventurer.pet.packages);
```
```typescript
Typemon [ 'ioc-container' ]
```

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