Open spruce-bruce opened 8 years ago
Sort of answering my own question, here. I did this:
ioc.use(function(id) {
if (id === 'server') {
server['@literal'] = true;
return server;
} else {
return;
}
});
Which is essentially the same code that's found in the node_modules
loader. This seems to work just fine so far... I'm wondering if there's any obvious problem with this that I'm missing?
That's a neat workaround to add individual objects into electrolyte. Note the else ... return
statement is not needed though, as the function returns the same value, undefined
, without it.
ioc.use(function(id) {
if (id === 'server') {
server['@literal'] = true;
return server;
}
});
Indeed!
Thanks :)
in Version > 0.1 (0.0.6) there was
ioc.literal("server", {});
Which is now an undocumented breaking change...
So you don't know why that was removed?
Singleton got renamed to literal, which broke the old meaning of it.
Thanks for this. Super basic need for a DI framework.
I'm using hapi.js and I'd like to add the hapi server object to my electrolyte container while at the same time maintaining some of hapi's best practices.
The hapi server object maintains its own container of plugin objects, and a typical way to set up a hapi project is to use a 'bootstrap' plugin to set up the server. Mine looks like this:
I want to make the server object that is passed into this plugin available in my electrolyte container. Is there some way to call
ioc.use
such that it will just make the already instantiated server object available in the container?