You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a singleton class that is being injected into other classes using the injected(...) syntax.
The class is called Exchange.
I need to add an async initializer to that class. (want to set up a websocket before the class is used)
I'm trying to do so by creating a Factory but I'm running into a roadblock. Can I still used injected() when using an async Factory?
.bind(TOKENS.exchange)
.toInstance(ExchangeAlpaca)
.inSingletonScope();
container
.bind(TOKENS.exchangeFactory)
.toFactory(async () => {
let e = container.get(TOKENS.exchange);
await e.init();
return e;
});
class SomeClass {
constructor(private e: Exchange){}
}
injected(SomeClass, TOKENS.exchangeFactory.optional) // <- this doesn't work
injected(SomeClass, TOKENS.exchange.optional) // <- this works but factory doesn't get used.
The text was updated successfully, but these errors were encountered:
I have a singleton class that is being injected into other classes using the
injected(...)
syntax.The class is called
Exchange
.I need to add an async initializer to that class. (want to set up a websocket before the class is used)
I'm trying to do so by creating a Factory but I'm running into a roadblock. Can I still used
injected()
when using an async Factory?I have tokens defined as follows:
and container bindings set up like this,
The text was updated successfully, but these errors were encountered: