1.0.6 • Published 1 year ago

ts-simple-ioc v1.0.6

Weekly downloads
2
License
MIT
Repository
github
Last release
1 year ago

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