ioc-registry v0.0.1
IOC Registry
Synopsis
A registry that provides a single location to register modules or objects which can be then be retrieved by other modules in an app. This allows parts of a codebase to use a module (or 'service') which is provided by the app and for the implementation to be easily replaced during different runtimes, for example during testing. It also provides the beneft that features can be implemented in isolation from the dependency, relying only on an interface rather than implementation details.
The ideas for IOC registry were taken from the 'service registry' and 'alias registry' in BladeRunnerJS but has been changed to provide a more generic solution which doesn't rely on specific bundling behaviour provided by the BladeRunnerJS toolkit.
Motivation
app-service-registry
and app-alias-registry
were created during a dev week which aimed to demonstrate libraries written using BladeRunnerJS could be used with WebPack and other libraries from NPM. As new features were imagined for each project it was apparent that the feature set was almost identical and a single registry could be used to register both module implementation and object instances, hence ioc-registry
was born.
It's also a good hobby project to write a Node library, investigate test tooling in Node and an opportunity write more code.
Installation
npm install ioc-registry --save-dev
Code Example
App:
var iocRegistry = require("ioc-registry");
iocRegistry.register('real-time-service', new PusherRealTimeService())
OR
iocRegistry.register('real-time-service', new PubNubRealTimeService())
OR
iocRegistry.register('real-time-service', new FirebaseRealTimeService())
Feature1:
var iocRegistry = require("ioc-registry");
var realTimeService = iocRegistry.resolve('real-time-service');
realTimeService.subscribe('some-data', callback);
Feature2:
var iocRegistry = require("ioc-registry");
var realTimeService = iocRegistry.resolve('real-time-service');
realTimeService.subscribe('more-data', callback);
Feature3:
var iocRegistry = require("ioc-registry");
var realTimeService = iocRegistry.resolve('real-time-service');
realTimeService.publish('cool-data', 'lotsa data!');
API Reference
Tests
Tests are in tests
directory can are run via Mocha and Karma.
npm test
to run both sets of tests.npm run test:node
to run tests via Mocha in a Nodenpm run test:browser
to run tests via Karma in Firefoxnpm run test:saucelabs
to run tests using Karma and browsers hosted by SauceLabs
When developing:
npm run test:dev
to run tests via Mocha, automatically re-running tests on file changesnpm run test:browser:debug
to run tests via Karma, persisting the browser and automatically re-running tests on file changes
Contributors
Let people know how they can dive into the project, include important links to things like issue trackers, irc, twitter accounts if applicable.
License
A short snippet describing the license (MIT, Apache, etc.)
8 years ago