# @kingga/kc-container

> A simple IoC container for the kings collection.

Latest version **1.0.3** (published 2019-11-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install @kingga/kc-container
pnpm add @kingga/kc-container
yarn add @kingga/kc-container
bun add @kingga/kc-container
```

## 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.3 |
| Published | 2019-11-29 |
| First published | 2019-10-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 41.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Isaac Skelton |
| Maintainers | kingga |
| Keywords | IoC, Kings Collection, Container, JavaScript, TypeScript, Container |

## Links

- npm: https://www.npmjs.com/package/@kingga/kc-container
- npm.io page: https://npm.io/package/@kingga/kc-container

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2019-11-29
- 1.0.2 — 2019-11-23
- 1.0.1 — 2019-10-25
- 1.0.0 — 2019-10-25

## README

# Kings Collection IoC Container
[![Build Status](https://travis-ci.com/kingga/kc-container.svg?branch=master)](https://travis-ci.com/kingga/kc-container)

A simple IoC container for the kings collection. Inspired by the [Laravel container](https://laravel.com/docs/6.x/container)!

## Installation
### Yarn
`yarn add @kingga/kc-container`

### NPM
`npm i @kingga/kc-container`

## Usage
```ts
import Container from 'kc-container';

const container = new Container;

class Foo {
    toString(): string {
        return 'foo';
    }
}

class Faz {
    public readonly foo: Foo;

    public constructor(foo: Foo) {
        this.foo = foo;
    }
}

class State {
    protected hiddenState: object = {};

    public set state(state: object) {
        this.hiddenState = state;
    }

    public get state(): object {
        return this.hiddenState;
    }
}

// Simple bindings.
container.bind(Foo, () => new Foo);
container.bind(Faz.name, (app: Container) => new Faz(app.make<Foo>(Foo)));

// Singletons.
container.singleton(State, () => new State);

// Getting something from the container.
const stateA = container.make<State>(State);
stateA.state = { foo: 'bar' };

const stateB = container.make<State>(State);
it('should be the same since it is a singleton', () => strictEqual(stateA, stateB));
```

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