inversionist v1.0.0
Inversionist
Inversionist is a dependency injection container for JavaScript and TypeScript. It is a simple tool to help you build a loosely coupled and testable system.
Installation
You can install Inversionist using npm
npm install --save inversionistExample
To create a container
import { Container } from 'inversionist';
const container = Container.create();To register an injectable instance
class HttpService {}class UserService() {
constructor(httpService) {}
}container
.register('httpService', container => {
return new HttpService();
})
.register('userService', () => {
return new UserService(container.get('httpService'));
});To register a service as a singleton
container.registerSingleton('httpService', container => {
return new HttpService();
});To get an instance out of the container
container.get('userService');If you are using this library in a TypeScript project, you can specify the return type of a get call.
container.get<UserService>('userService');Development
The source code is written in TypeScript. To compile to JavaScript, please run
npm run buildTo run tests, please run
npm testTo see a test coverage report, please run
npm run coverageTo lint your code, please run
npm run lintContribution
If you like to contribute, please make a pull request explaining your changes. If you want to make a suggestion or file a bug report, please create a GitHub issue.
License
MIT