refactor(ng-lib): manage HttpClient dependency #144
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
ComponentsModule.forRoot
only providesHttpClient
, but not its dependencies.Pull Requests: #69 #75
Issue Number: #52
What is the new behavior?
Instead of providing only
HttpClient
, but not its dependencies, we now re-exportHttpClientModule
in the staticforRoot
method ofComponentsModule
.I have also added a test suite for the
ComponentsModule
which exercises injectingHttpClient
and its dependencies.Does this PR introduce a breaking change?
Other information
Note that the
init
schematic currently addsHttpClientModule
to the consumersAppModule
imports
.Sorry for bringing this up again, but the current implementation only provides
HttpClient
. I did some digging and discovered thatHttpClientModule
actually provides quite a few dependencies used byHttpClient
at runtime.How do we want to handle this?
In the new approach of this PR, I simply re-export
HttpClientModule
inComponentsModule.forRoot
.Usually, we would just expect the consuming application to inject
HttpClientModule
. The classes depending onHttpClient
(ScullyRoutesService
andScullyContentComponent
) would crash at runtime, ifHttpClient
and its dependencies were not provided by the consuming application.Is this a better option? Then we can remove the static
forRoot
method instead. If so, we could probably detect the error early by attempting to injectHttpClient
inComponentsModule
's constructor as an optional dependency and throw an error with a helpful message if it could not be resolved.