1.0.0 • Published 7 years ago

inversionist v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

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.

Build Status

Installation

You can install Inversionist using npm

npm install --save inversionist

Example

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 build

To run tests, please run

npm test

To see a test coverage report, please run

npm run coverage

To lint your code, please run

npm run lint

Contribution

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