dependency-container-js v2.0.0-beta1
"dependency-container-js" is a simple IOC container pattern for NodeJS.
You can get the latest release from the official npmjs.com feed or from the github releases page.
Getting Started
Importing the module and initializing an instance
// Import the module.const DependencyContainer = ; // Initialize an instanceconst diContainer = ;
Registering services.
// Registering a service as singleton.diContainer; // Registering a service as transient.diContainer;
Injecting IoC container to components.
// Register component named 'DummyController'.diContainer;
Resolving a service
// Resolve service named 'DummyController'.const dummyController = diContainer;
Full demonstration:
Content of DummyService.js:
/** * DummyService is a dummy service to demonstrate how to register a service for an IoC * container. * @class DummyService */ /** * Gets the necessary message. */ { return 'Hello there!'; } moduleexports = DummyService;
Content of DummyController.js:
/** * DummyController is a dummy component to demonstrate how to resolve * registered dependencies. * @class DummyController */ /** * Initializes an instance of the DummyController. * @param * @param */ { // Resolve necessary dependencies. this__dummyService = ioc; // this.__myOtherLovelyService = ioc.resolve('OtherLovelyService'); // Assign options to the local field. this__options = options; } /** * Writes the necessary message to the console. */ { console; } moduleexports = DummyController;
Content of index.js
// Import the module.const DependencyContainer = ; // Import dependent modules.const DummyController = ;const DummyService = ; // Initialize an instance of the DIController.const diContainer = ; // Register.diContainer // Consider, this is another block of code from another js module.const controller = diContainer;controller;
Versioning
Used SemVer for versioning. For the versions available, see the tags on this repository.
Authors
- Deniz Kanmaz (denizkanmaz@gmail.com) - Initial work
License
This project is licensed under the MIT Licece - see the LICENSE.md file for details.
NOTICE: This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.