
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
javascript-dependency-injection
Advanced tools
Javascript Dependency Injection library (ES2015)
DI makes classes accessible by a contract. Instances are created when requested and dependencies are injected into the constructor, facilitating lazy initialization and loose coupling between classes.
As an example, consider a User and Persitance classes:
class FileDB {
constructor(fs, tableName, listOfFields) { .... }
persist(record) { .... }
}
class User {
constructor(email, passwd, storage, role) { ... }
save() { this.storage.persist(this); }
}
To define the relation between both classes use DI#register
import fs from 'fs';
var di = new DI();
di.register('$user', User, [null, 'welcome', '$fileDb', 'nobody']);
di.register('$fileDb', FileDb, [fs, 'user', ['email','passwd', 'role']], {singleton: true});
The 1st argument of DI#register is the name of the contract, the 2nd the class reference, the 3rd an array
of the constructor arguments and the last a config object. Currently ther config has only 2 options
- singleton, it only create the instance once
- notAClass, meaning that the reference is not a class
To get instances do
di.getInstance('$user', 'test@di.com');
or if you also wish to change the role
di.getInstance('$user', 'test@di.com', null, null, 'admin');
For more advanced use-cases checkout the unit tests file.
You can find a detailed API description + a code-coverage report here
Install the dependencies as follows
$> npm install --save javascript-dependency-injection@beta
Unit testing is can be done as follows
$> npm test
it will also open the code-coverage report
$> npm run doc
FAQs
Javscript dependency injection library
We found that javascript-dependency-injection 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.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

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.