npm.io
1.8.0 • Published 8 years ago

najs-binding

Licence
MIT
Version
1.8.0
Deps
1
Size
73 kB
Vulns
0
Weekly
0
Stars
1

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