containor

Simple DI container for Javascript with Typescript support

Usage no npm install needed!

<script type="module">
  import containor from 'https://cdn.skypack.dev/containor';
</script>

README

Containor Logo

Containor

Build Status

Simple DI container for Javascript with Typescript support.

  • Supports any programming style.
  • Typescript support.
  • Resolve dependecies async.
  • Does not make any assumptions on your stack.
  • No dependencies! 🎂

Containor weighs just ~4kb minified!*

📖 Documentation

Getting started

Installation

Containor can be installed by using any package manager using the npm repository.

npm install containor

With yarn:

yarn add containor

Containor ships with Typescript types included, these do not have to be installed separately.

Basic usage

import { createContainer, token } from "containor";

class Foo {
  constructor(bar: Bar) {
    this.bar = bar;
  }
}

class Bar {}

const tokens = {
  foo: token<Foo>("foo"),
  bar: token<Bar>("bar"),
};

const container = createContainer();

container.add(tokens.foo, Foo, [tokens.bar]);
container.add(tokens.bar, Bar);

const foo = container.get(tokens.foo); // An instance of Foo with Bar injected.