
Security News
Feross on the 10 Minutes or Less Podcast: Nobody Reads the Code
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.
Omni stands for "One More NodeJS dependency Injector". Clean, powerful, and expressive name-based DI for NodeJS
npm install omni-di
Fundamentally, omni takes a function, inspects the function's parameter names, and executes the function with the parameters as identified by their names. A common use case is building up routes for use in ExpressJS without having to do explicit require calls in every route file:
// app.js
var request = require('request');
var google = require('./routes/google.js');
di.register('request', request);
app.get('/google', google.get.inject(di));
// routes/google.js
exports.get = function(request) {
return function(req, res) {
// Use request module...
}
};
var di = require('omni-di')();
// Can register and inject dependencies
di.register("a", 1)
var fn = di.inject(function (a) {
return function() {
return ++a;
}
})
fn() // 2
fn() // 3
// Can register and inject with one function call
di.injectAndRegister('b', function(a) {
return a + 1;
});
di.inject(function(b) {
console.log(b); // 2
});
// Can register and inject dependencies
di.register("a", 1);
di.get('a') // 1
// Can assemble your dependency graph
di.assemble([
[
{ name : 'fs', obj : require('fs') },
{ name : 'config', obj : { file : 'test.txt' } }
],
[
{
name : 'configFile',
factory : function(fs, config) {
return JSON.parse(fs.readFileSync(config.file));
}
],
[
{
name : 'doStuffWithConfig',
factory : function(configFile) {
// Do things with JSON config
}
]
]);
di.inject(function(fs, configFile) {
// Do things with fs and configFile
});
var omni = require('omni-di');
// Attaches a convenience helper .inject(di) to Function.prototype
omni.addInjectToFunctionPrototype();
var di = omni();
di.register("a", 1);
// Use attached .inject() for syntactic sugar
function(a) {
console.log("a"); // 1
}.inject(di);
FAQs
Lightweight argument-based dependency injection
We found that omni-di demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.