Closed TriumphTruth closed 4 years ago
See my answer here: https://github.com/ngx-rocket/generator-ngx-rocket/issues/432#issuecomment-455982764
There is many ways to avoid circular dependency issues, I suggest you to look at this article: https://medium.com/visual-development/how-to-fix-nasty-circular-dependency-issues-once-and-for-all-in-javascript-typescript-a04c987cf0de. You can also use a state management library, like https://www.ngxs.io: event-based actions design pattern is an easy way to avoid such issues.
BTW, included HttpService
is provided when you use HttpClient
injection token, as seen in your error stack trace. The error in that one seems to be something different.
I think what you are suggesting is to create a new service that will solely perform the, in my case Refresh Token functionality.... While it seems to be a way, will I will try and update for sure, but appears to me as a not so fancy way of bypassing this problem.
Additionally I don't think it should resolve the problem.... The problem stems from the following circular chain:
1 - ALL Services inherits HttpService
2 - Whenever we make a call using HttpService
it injects the HttpInterceptors
which are API, Error etc
.
3 - If any of the interceptor is making a call using any service or within itself, it is again starting the same chain from step 1.
But will still try your advice and update the issue accordingly.
FWIW, upcoming version will provides 2 answers to avoid this issue:
core
module.
I'm submitting a...
Current behavior
I am trying to catch the 401 errors in the
ErrorHandlerInterceptor
and based on that trying to make a call to get a new refresh token.But doing so is resulting in circular dependency, if I use the existing
HttpService
/AuthenticationService
/ErrorHandlerInterceptor
itself.My Error Handler
Now firstly I put this in the AuthenticationService. But it was giving me Circular Dependency error. Then I put it in the ErrorHandler itself.... It again gave me Circular Dependency error. The I omitted using the out of the box HttpService. And injected Angular's HttpClient. Then I get the following error:
Expected behavior
I should be able to make a call to get a new token.
Minimal reproduction of the problem with instructions
Environment
Others:
Please guide how do I implement a refresh token functionality without this circular dependency.