Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
This module provides dependency injection for node.js
npm i hekdi
hekdi
popular frameworks integration:// imported.module.js
const { createModule } = require('hekdi');
class Dependency1 {
constructor() {
this.name = 'Dependency1';
}
}
class Dependency2 {
static get $inject() {
return ['LocalDependency'];
}
constructor(d1) {
this.name = 'Dependency2';
this.d1 = d1;
}
}
module.exports = createModule({
name: 'ImportedModule',
declarations: [
{ name: 'LocalDependency', strategy: 'singleton', value: Dependency1 },
{ name: 'PublicDependency', strategy: 'factory', value: Dependency2 },
{ name: 'Arr', strategy: 'value', value: [1, 2, 3] }
],
exports: ['PublicDependency', 'Arr']
});
// main.module.js
const { createModule } = require('hekdi');
const importedModule = require('./imported.module');
class Ctrl {
static get $inject() {
return ['PublicDependency', 'Arr'];
}
constructor(publicDep, arr) {
console.log(publicDep, arr);
}
}
module.exports = createModule({
name: 'SharedModule',
declarations: [
{ name: 'Controller', strategy: 'singleton', value: Ctrl },
{ name: 'ControllerAs', strategy: 'alias', value: 'Controller' }
],
imports: [ importedModule ]
})
// app.js
const { DI } = require('hekdi');
const MainModule = require('./main.module');
const di = DI.create();
di.bootstrap(MainModule);
const ctrl = di.resolve('ControllerAs');
// Dependency2 { name: 'Dependency2', d1: Dependency1 { name: 'Dependency1' } } [ 1, 2, 3 ]
Top level api is DI
class that bootstraps main module and serves dependencies from it then.
const { DI } = require('hekdi');
const di = DI.create();
di.module(moduleConfig) // creates new module from config
di.bootstrap(moduleConfig) // register module as main one and resolve dependencies from it
const dep = di.resolve('dependency') // return dependency that was registered to bootstrapped module according to its strategy
DI provides modules as a structural unit of app.
declarations
array sets own dependencies of this module.exports
array tells what dependencies are available for other modulesimports
array will inject exported members from other module to this oneconst { createModule } = require('hekdi');
createModule({
name: 'SomeModule',
declarations: [
{ name: 'LocalDependency', strategy: 'singleton', value: class X {} },
{ name: 'PublicDependency', strategy: 'factory', value: class Y {} },
{ name: 'Arr', strategy: 'value', value: [1, 2, 3] },
{ name: 'ZProvider', strategy: 'provider', value: () => ({ name: 'Z', strategy: 'factory', value: class Z {} })}
],
exports: ['PublicDependency', 'Arr'], // if '*' set, module will export all of the dependencies including imported
imports: [ AnotherModuleInstance ]
});
// here 'LocalDependency' will be available for injection only for members of this module.
factory
- each time a new instance will be created.singleton
- only one instance will be created.value
- just will be returned.constant
- the same as value
but can't be reassign.alias
- used to create an alias for some dependency.provider
- function that will be called, to get dependency config.
Providers register dependencies before others do. Providers can't be exported from module.FAQs
Depedency injection framework for node integrated with koa.js
The npm package hekdi receives a total of 10 weekly downloads. As such, hekdi popularity was classified as not popular.
We found that hekdi 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.