Singular is modular applications boilerplate. It's using for dependency injection in angular-like way with dependency resolving and asynchronous lazy initialization.
Installation
Singular could be installed with NPM:
npm i singular
Example
Singular is made for simple configuration and initialization:
const Singular = ;const singular = config: mongo: host: 'localhost' port: 27017 base: 'testBase' redis: host: 'localhost' port: 6379 users: minAge: 18 ; singular;singular; { // Get config and initialized mongo and redis clients const config db redis = await singular; configusersminAge; // => 18 // ...} // ...
Usage and API
Instantiate and configure new singular instance.
const Singular = ; const config = debug: true dir: __dirname; const singular = config;
Define factories and values using method module
. You can do it with methods value
or factory
too.
singular;
Inject dependencies with inject
method. Inject has aliases configure
and run
.
// Inject logger and log somethingsingular; // Regular promisesingular;