Providing functional interceptors without providing HttpClient

176 views Asked by At

There is now new method of providing HttpClient as provideHttpClient function. This also can take withInterceptors() function to define interceptors.

I have shared module as a separate dependency that defines few interceptors but does not import HttpClient (I leave it to applications themselves). As using HTTP_INTERCEPTORS thing is marked as "can be phased out in future", is there any way to provide functional interceptors without importing whole HttpClient? Something like adding withInterceptors() to providers array.

I can't actually provide array of interceptors as module itself takes crucial required config that is then used by interceptors. Additionally module also exposes bunch of services so it's more comfortable to just import one module.

1

There are 1 answers

0
Matthieu Riegler On

This is not possible and this is not wishable !

This was a deliberate design choice of the new API; interceptors are sensitive to ordering and the registration of the HTTP services to actually consider those interceptors, so the API was designed such that both ordering and the registration is determined in a single place.

Interceptors should be define in a single point to ensure the predictability of their order.

So if you have a lib, you will have to export/expose them.

For more info, look at this issue.