Keep CoreModule as preferred location for app-wide single-use components
See original GitHub issueπ Docs or angular.io bug report
Description
The CoreModule guidelines have recently been removed from the style guide. While the CoreModule is indeed not relevant for providing app-wide singleton services now that we have the providedIn
option in the @Injectable()
decorator, the style guide also gave it another purpose.
The CoreModule was the place to go for declaring app-wide single-use components, such as a navigation bar or menu.
I think this recommendation could still be relevant in the style guide.
π¬ Minimal Reproduction
Whatβs the affected URL?**
https://angular.io/guide/styleguideExpected vs Actual Behavior**
The CoreModule guidelines have been completely removed from the style guide.
I think that the CoreModule is still a great place to declare app-wide single-use components, along with their dependencies, which would otherwise add some unnecessary cluttering to the AppModule.
The SharedModule would not be a good location for these components, since they are not βactuallyβ re-usable.
While it is a pretty opinionated choice, I find it useful to have a common place amongst all projects for these specific components, as it used to be the case for app-wide singleton services (I still tend to keep these in a services
sub-folder of the core
folder, because I find it kind of weird to have a services
folder directly under app
, alongside feature modules folders).
Feel free to weigh in on this proposal, Iβll be very happy to discuss it further ! πΈ
Anything else relevant?
This issue refers to PR #28434 by @kapunahelewong
Issue Analytics
- State:
- Created 4 years ago
- Reactions:14
- Comments:7 (6 by maintainers)
This is all great feedback. Now that services can be provided in the root using
providedIn
it does make it easier to put services where they are needed.However, the CoreModule was never intended to be a place to put services that should only be defined and used in a sub-ngmodule. So here are my thoughts on this, with some questions to consider.
My domain here is to consider app-wide services. Not ones used only in a sub-ngmodule. What about services used app-wide by needing to be defined in a sub module? Letβs hold off on that for a moment.
First - app-wide stuff in the root β¦
AppModule
? If so, are you comfortable with having a dozen or so of them defined there? Possibly.I do think there is some value for a CoreModule for organizational purposes. (see above)
But β¦ what about a service that a sub module needs and some other one might need. Could you define that in a sub module? Well, you could β¦ letβs walk through that. Assume we have a Customer ngmodule and we define a
CustomerService
that gets and puts customer data and it usesprovidedIn
to the root. Now another module needs Customer data. You could still use it in that other ngmodule, letβs say it handles Orders. So the ngOrders module now uses a service that is provided in the root, but exists in the Customer Module. This works. But is is clear? Is it readable?New questions based on this new scenario β¦ How does lazy loading of OrdersModule work now that it depends on a service in the CustomersModule (which is provided in the root)? Is it confusing? What happens if you re-use OrdersModule in another app? It has a dependency that you now need to track down?
IMO - any app-wide βthingsβ should be easily findable. Thus the concept (not the name though) of a CoreModule is still valid and I still use it.
Hope this helps π
Status: docs team needs to partner with engineering to determine next steps. Great context info above!