Skip to content

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

License

Notifications You must be signed in to change notification settings

najs-framework/najs-binding

Repository files navigation

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


About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •