najs-binding
TypeScript icon, indicating that this package has built-in type declarations

1.8.0 • Public • Published

Najs Binding

A simple and powerful dependency injection, service container, instance resolver for Node applications

Travis Maintainability Coverage Status node version npm version npm downloads npm license PRs Welcome

What is Service Container?

The Service container is a powerful tool for managing class dependencies and performing dependency injection.

For example, suppose you have a simple UserService class that contains all users from database:

// written in Javascript
class UserService {
  @autoload('UserRepository') userRepository
 
  getUsers() {
    return this.userRepository.getUsers()
  }
}

In this example, the UserService needs to retrieve users from a data source. So, we will inject a repository that is able to retrieve users. Since the repository is injected, we are able to easily swap it out with another implementation. We are also able to easily "mock", or create a dummy implementation of the UserRepository when testing our application.

Usage

API

register()

make()

bind()

@autoload()

ClassRegistry

License

MIT @ Nhat Phan


Readme

Keywords

none

Package Sidebar

Install

npm i najs-binding

Weekly Downloads

5

Version

1.8.0

License

MIT

Unpacked Size

74.9 kB

Total Files

49

Last publish

Collaborators

  • najs