-
Notifications
You must be signed in to change notification settings - Fork 26.5k
Closed as not planned
Labels
area: common/httpIssues related to HTTP and HTTP ClientIssues related to HTTP and HTTP Clientcross-cutting: resourceIssues related to the newly introduced resource / httpResourceIssues related to the newly introduced resource / httpResource
Milestone
Description
Which @angular/* package(s) are relevant/related to the feature request?
common
Description
In our project we use modular HttpClient with different setup of interceptors for accessing different API's.
We create createHttpClient
helper for that:
export function createHttpClient(...features: HttpFeature<HttpFeatureKind>[]): HttpClient {
assertInInjectionContext(createHttpClient);
const injector = createEnvironmentInjector(
[provideHttpClient(...features)],
inject(EnvironmentInjector),
);
return injector.get(HttpClient);
}
And we use this helper inside {provide: CUSTOM_HTTP_CLIENT_TOKEN, useFactory: () => createHttpClient()}
.
It works until we migrate to httpResource
, because there is no way to specify what instance of HttpClient
should be used.
Proposed solution
Add option httpClient?: HttpClient
to HttpResourceOptions
.
Alternatives considered
Create custom injection context, and run httpResource
inside it:
function bindHttpResource<T>(resourceFactory: () => HttpResourceRef<T>, httpClientToken: InjectionToken<HttpClient>): HttpResourceRef<T> {
assertInInjectionContext(bindHttpResource);
const injector = Injector.create({
providers: [{
provide: HttpClient,
useExisting: httpClientToken,
}],
parent: inject(Injector),
});
return runInInjectionContext(injector, resourceFactory);
}
Metadata
Metadata
Assignees
Labels
area: common/httpIssues related to HTTP and HTTP ClientIssues related to HTTP and HTTP Clientcross-cutting: resourceIssues related to the newly introduced resource / httpResourceIssues related to the newly introduced resource / httpResource