gund / ng-http-interceptor

Http Interceptor library for Angular
MIT License
104 stars 16 forks source link

How can we Register interceptors globally ?? #137

Closed teswar closed 7 years ago

gund commented 7 years ago

Did you go through the example use case? You can set interceptors that way from any component or service you want.

teswar commented 7 years ago

Yes, did go through this example , but there you are adding/removing interceptors probably in a service level. I think it would be better to configure the interceptors in the module level, while the HttpInterceptorService is being injected. As you have stated in your concept or as here

gund commented 7 years ago

The thing is services should always remain as singletons meaning they are only of one instance no matter where you are injecting it (any component or service).

That said all registered interceptors always global.

teswar commented 7 years ago

I understand the singleton concept. In my project there a independent service to each resources, where HttpInterceptorService is being injected via constructor and most of the API calls need OAuth Token attached to the header. The problem is I can't be certain which service will always be firstly created, so that the interceptors can be configured in that service. Else I have to configure in the base-service, which is inherited by all my resource-services.

But I am able to do this in the main app's module level. I will not have to be worried about these rite ?

gund commented 7 years ago

I'm sure you can do that from main app.

However I'm not sure I can see the problem why you ever should be worried about services construction order? Can you please provide some example use case?

gund commented 7 years ago

I'm going to close this assuming your issue was resolved

teswar commented 7 years ago

Yeap. Thnx...