Skip to content
This repository has been archived by the owner. It is now read-only.
Switch branches/tags
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Simple, easy dependency injection framework for JavaScript.

Inspired by the $injector service in the Angular framework library, I built this from scratch as a standalone experiment in dependency injection for JavaScript.

It handles nested dependencies, avoids infinite recursion, takes multiple patterns for object creation, and uses annotations for dependencies that are minification-friendly. You may either set an array on the object to indicate the list of dependencies to inject into the constructor or specify the dependencies when you add the object to the container.

Learn more about jsInject in this blog post.

Create an instance of the container (you may have as many containers as you like, but they are not aware of each other):

var $jsInject = new $$jsInject();

$$jsInject can handle multiple patterns for object creation:


function serviceA(dependencyB) {
    return {
      id: dependencyB.getId()

Constructor Function

function ServiceA(dependencyB) { = dependencyB.getId();

Self-Invoking Function

var ServiceA = (function() {
    function ServiceA(dependencyB) { = dependencyB.getId();
    return ServiceA;

Function Annotation:

ServiceA.$$deps = ["dependencyB"]; 
$jsInject.register("serviceA", [ServiceA]);

Registration-time Annotation

$jsInject.register("serviceA", ["dependencyB", ServiceA]);

Retrieving instances

var svcA = $jsInject.get("serviceA");
var depB = $jsInject.get("dependencyB");

Pass a unique name for the instance to the registration function, then an array. The array should either contain the function if the function itself is annotated with the special property $$deps, or a list of named dependencies followed by the function in an array if you want to annotate the dependencies at run-time.

See the tests to learn more.


Simple & easy DI for JavaScript.




No packages published