shmoop207 / appolo-inject Goto Github PK
View Code? Open in Web Editor NEWdependency injection for nodejs
License: MIT License
dependency injection for nodejs
License: MIT License
Say I have a module like this:
export default class M {
}
and I have a definition for this like below:
{
path: "./M",
singleton: true,
lazy: true
}
I get an exception from inject.js saying object is not a function. I tried forking your library and changing the code to this:
try {
//crate object instance
if (typeof objectDefinition.type === 'object') {
objectDefinition.type = objectDefinition.type.default;
}
newObjectInstance = new objectDefinition.type(...argumentInstances);
}
catch (e) {
throw new Error("Injector failed to create object objectID:" + objectID + "' \n" + e);
}
This way it works, not sure if I could achieve this without modifying your lib?
Thanks.
I know I can use inject to get a "new" instance when the class isn't defined with singleton:true
BUT: How can I use inject with a class that needs params in the constructor (in the new process)?
for example:
var AlertBase = Class.define({
$config: {
name: 'AlertBase'
},
constructor: function (warningMessage, receipents) {
this.message = warningMessage;
this.receipents = receipents;
}
});
var SpecificsAlert = AlertBase.define({
$config: {
id: 'SpecificsAlert',
name: 'SpecificsAlert',
extends: AlertBase,
alias: ['alert']
},
constructor: function (receipents, envName) {
var warningMessage = 'WARNING --!';
var payload = {
environment: envName
};
this.callParent(warningMessage, receipents);
}
});
How can I use inject for the SpecificsAlert class and pass it the expected params for the constructor?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.