1.1.1-depr1 • Published 2 years ago
inversification v1.1.1-depr1
Inversification
===================
Deprecation
Deprecated in favor of https://www.npmjs.com/package/@inversification/ioc
===================
A simple, lightweight, dependency-free and decorator-based IOC container for Node
Usage
Register a class with the @injectable
decorator:
// inject-me.ts
import { injectable } from 'inversification';
@injectable()
export class InjectMe {
doThings() {
console.log('A thing');
}
}
Inject your service with the property decorator @inject
:
// consumer.ts
import { inject } from 'inversification';
import { InjectMe } from './inject-me.ts';
export class Consumer {
@inject(InjectMe.name) private service: InjectMe;
callMe() {
this.service.doThings();
}
}
/********/
/********/
// main.ts
import { Consumer } from './consumer.ts';
const consumer = new Consumer();
consumer.callMe(); // >> 'A thing'