0.0.2 • Published 4 years ago

simple-ioc-lib v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

simple-ioc-lib

Build Status License Library minified size Library minified + gzipped size

What is simple-ioc-lib?

simple-ioc-lib is a simple dependency injection library seed written in Typescript.

Installation

This library is published in the NPM registry and can be installed using any compatible package manager.

npm install simple-ioc-lib --save

# For Yarn, use the command below.
yarn add simple-ioc-lib

Example

import { createToken, Container } from 'simple-ioc-lib';

const SERVICES = {
  Person: createToken('Person'),
  Logger: createToken('logger'),
};

interface IPerson {
  name: string;
}

interface ILogger {
  log(message: string): void;
}

class Person implements IPerson {
  constructor(public name: string = 'Adam') {}
}

class Logger implements ILogger {
  log(message: string) {
    console.log(message);
  }
}

const container = new Container();
container.register(SERVICES.Person, Person);
container.register(SERVICES.Logger, Logger);

const person = container.get<IPerson>(SERVICES.Person);
const logger = container.get<ILogger>(SERVICES.Logger);

logger.log(person.name);

Go to example folder.

Documentation

Documentation generated from source files by Typedoc.

License

Released under MIT License.

0.0.2

4 years ago

0.0.1

4 years ago