0.0.2 • Published 4 years ago
simple-ioc-lib v0.0.2
simple-ioc-lib
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.