1.2.1 • Published 5 years ago

lab-di v1.2.1

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

lab-di

Introduction

lab-di is a small dependency injection container based on BottleJS. It features directory loading, implementation handling.

Build a service with different implementations

└── service
    ├── implementations
    │   ├── memory.js
    │   └── real.js
    └── index.js

service/index.js

function Service(container) {
  const implementation = container.get('config').get(Service.serviceName);
  return container.getImplementation(Service.serviceName, implementation);
}

Service.type = 'factory';
module.exports = Service;

service/implementations/memory.js

function MemoryService (config) {
  // return with the memory implementation  
  return {};
}

MemoryService.deps = ['config'];
module.exports = MemoryService;

Register a service into the di container

using the di

const di = require('lab-di')();

di.registerModule(require('./module'), 'Module');
di.registerModule(require('./other'), 'Other');

using the tools

const diTools = require('lab-di/tools')();
diTools.registerDir(path.resolve(__dirname, 'services'));
const di = diTools.getDI();
1.2.1

5 years ago

1.2.0

7 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago