ts-simple-ioc
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

ts-simple-ioc

A simple IoC container for TypeScript, strongly influenced by Microsoft.Extensions.DependencyInjection.

Build Status

Features

  • Simple service registration & resolution
  • Type safe service resolution
  • No package dependencies
  • No requirement on services to know about the IoC framework, e.g. no decorators
  • Singleton & transient lifetime support
  • Constructor dependency injection
  • Property dependency injection

Getting started

Installation

npm install --save ts-simple-ioc

Registering and resolving services

import { Container } from "ts-simple-ioc";

class ExampleService {
    constructor(public dependency: ExampleDependency) {}
}

class ExampleDependency {}

const container = new Container()
    .addTransient(ExampleService, (resolve) => new ExampleService(resolve(ExampleDependency)))
    .addSingleton(ExampleDependency, () => new ExampleDependency())
    .beginResolution();

const service = container.resolve(ExampleService);

Roadmap

  • v1.1.0
    • Scoped lifetime support
  • v1.2.0
    • Circular dependency detection

/ts-simple-ioc/

    Package Sidebar

    Install

    npm i ts-simple-ioc

    Weekly Downloads

    1

    Version

    1.0.6

    License

    MIT

    Unpacked Size

    10.4 kB

    Total Files

    15

    Last publish

    Collaborators

    • carl-hartshorn