Mock providers not cached
var di = require('di');
function Bar() {}
di.annotate(Foo, new di.Inject(Bar));
function Foo() {}
di.annotate(BarMock, new di.Provide(Bar));
function BarMock() {
console.log('initialise BarMock');
}
var injector = new di.Injector([BarMock]);
injector.get(Foo);
injector.get(BarMock);
I expect that BarMock should only be initialised once, as the second time I call injector.getPromise, BarMock has already been initialised – the subsequent request should fetch the cached version.
I am seeing:
$ node test
initialise BarMock
initialise BarMock
I expect:
$ node test
initialise BarMock
@vojtajina Really keen to fix this. Any pointers?
Maybe related to this todo in injector.js ?
// TODO(vojta): handle these cases: // 1/ // - requested as promise (delayed) // - requested again as promise (before the previous gets resolved) -> cache the promise
i have the same problem without using Provide
i've confirmed with a quick modification that it is due to this unhandled use case. I'll try to make a pull request including tests quickly