Dependable Dependency Injection Framework

1.1.0 · maintenance · verified Tue Apr 21

Dependable is a minimalist dependency injection (DI) framework specifically designed for Node.js environments. It currently stands at version 1.1.0, a stable release, but exhibits a very low release cadence, with the last significant update being a number of years ago, despite minor recent commits on its GitHub repository. Its core functionality revolves around automatic dependency resolution through function argument introspection, allowing for lazy loading of dependencies. Key differentiators include its simple API for registering and resolving dependencies, support for re-registering components (useful for configuration or mocking), and the ability to override dependencies at resolve time. Unlike more comprehensive modern DI containers like InversifyJS or Awilix, Dependable focuses purely on a lightweight, convention-based approach, omitting features such as explicit type binding, decorator-based configuration, or native asynchronous dependency resolution. This makes it suitable for projects prioritizing simplicity and minimal overhead.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a Dependable container, register various types of dependencies (strings, objects, functions with auto-injected arguments), and resolve them. It also shows how to re-register dependencies for dynamic changes and override them at the point of resolution for flexible behavior and testing.

const dependable = require('dependable');
const container = dependable.container();

// Register simple dependencies
container.register('occupation', 'tax attorney');
container.register('transport', {
  type: 'station wagon',
  material: 'wood-paneled'
});

// Register a dependency that has other dependencies
container.register('song', function (occupation, transport, legalStatus) {
  const song = {};
  song.chorus = function chorus() {
    return [
      'I\'m a ' + occupation,
      'On a ' + transport.material + ' ' + transport.type + ' I ride',
      'And I\'m ' + legalStatus.message
    ].join('\n');
  };
  return song;
});

// Register a dependency out-of-order (lazy resolution)
container.register('legalStatus', {
  warrants: [],
  message: 'without outstanding warrants'
});

// Resolve and use a dependency
container.resolve(function (song) {
  console.log('Original song:\n' + song.chorus());
});

// Re-register dependencies for updated behavior (e.g., for testing)
container.register('occupation', 'cowboy');
container.register('legalStatus', {
  warrants: [
    {
      for: 'shooting the sheriff',
      notes: 'did not shoot the deputy'
    }
  ],
  message: 'wanted: dead or alive'
});

// Resolve with updated dependencies (empty override to force re-evaluation)
container.resolve({}, function (song) {
  console.log('\nUpdated song:\n' + song.chorus());
});

// Override dependencies at resolve time
const horse = {
  type: 'horse',
  material: 'steel'
};

container.resolve({ transport: horse }, function (song) {
  console.log('\nOverride transport song:\n' + song.chorus());
});

view raw JSON →