Closed comatory closed 3 years ago
Also the _injector
is created once. I am using class to map dependencies on the injector and then I'm accessing _injector
in different methods.
When I try to print out _injector.getAll()
I get empty ()
so not sure what that is about.
So after doing some deep diving into my own code, I realized that this is a problem with circular dependency. This was not obvious from the start because in the constructor of one of the dependencies I was creating an instance of service. This service was not managed by DI mechanism and I was passing dependencies directly in there. Unfortunately for me, this service shared the same class that I was trying to use at the same time.
So solution was straightforward from there. The new dependency I created could not use apiB
dependency, instead I created another service that serves as a mediator.
It's probably hard to catch Stack Overflow
error but if it would be possible, it'd be great to throw custom library error that would give you a hint that you might be attempting to do this. But I assume that it's not something that could be detected in runtime.
You can close this issue, no bug whatsoever.
Sorry missed this. Yes good idea - I'll try and add a circular dependencies error
Hi. Great package, however I'm running into some nasty error which might or might not be caused by your plugin.
I am using couple of
map
methods and some of them are not singletons. It looks like thisThen when I use it later in the code:
When I add the line
apiB: i.get<ApiB>()
it throws this errorIt only happens when I pass
apiB
dependency toUserRepository
constructor. I found out if I removeand change it to
The error no longer happens. This is not a "fix" as I obviously need the dependency there but it's a point where it fails.
I am aware that this error could be thrown for any number of reasons but would you have any idea where to start looking at the problem? It seems to instantiate
ApiB
instance just fine. I have checked ifAuthorizedApiClient
is really being created twice just to make sure (because my code expects eachapiClient
to be separate instance) by printing outhashCode
and they are indeed different.