-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Distinguish CoreModule from AppModule or drop it #17825
Comments
there seem to be two definitions for
the other one is:
|
Thanks for this @dancancro. We've been working on re-thinking the presentation of the NgModules related documentation and the If you have ideas on clarifying further, please feel free to comment #20306. |
I've always looked at CoreModule vs SharedModule from the point of DI and LazyLoading (taking into acount that a lazy loaded module has it's own DI container), where a CoreModule only contains providers and is imported into the AppModule. SharedModule on the other hand contains anything but providers (unless there's certain providers which should not be singleton in the case of LazyLoading). In most libraries (aswell as the Angular Router) I see them being implemented as Note: This might not be 100% the same as the Core- and SharedModule definitions, as forRoot mostly includes the declarations aswell, but the idea behind it sounds the same to me (all about DI). Looking at this, I'm not sure if there's a need for an explicit Core and SharedModule, in practice I often see multiple modules which either act as a Core- (providers for the root) or SharedModule (declarations, pipes and none-singleton providers) in a single (probably larger) project. Don't get me wrong, I do think the idea behind both CoreModule and SharedModule is important, not sure if there's to be only one of them (nor do they have to be named Core or SharedModule), which is exactly what people are doing coz the docs mention them explicitly like that, resulting in big Core- or SharedModules. I remember starting with Angular, being told I need a CoreModule and SharedModule (without a real reason why). When I explain both CoreModule and SharedModule, I mostly start with explaining how DI works in case of LazyLoading and how both of them are useful in this situation (by explaining the problems, and how they are solved by both of the Module "types"). I've also seen CoreModules which act as a Module to keep AppModule clean, making AppModule only responsible for bootstrapping the App. Imho this is a nice idea, but it's something unrelated to the above CoreModule definition.
I don't think CoreModule is the same as AppModule, as you're also using so-called |
Current text makes a distinction/definition here: I didn't review all text around other uses of CoreModule to make sure we're clear in those instances about it being a convention, but some were clear about this. Issue possibly resolved when we merged ngModules update earlier this year. Keeping open to double-check. |
Fwiw the CoreModule and ShareModule definition used on AIO (https://angular.io/guide/ngmodule-faq#coremodule) are clear to me. However, it can still be a bit hard to understand for people not familiar with the reasoning behind it. Afaik both the CoreModule and SharedModule come from a DI perspective in combination with LazyLoading. I currently see quite some developers blindly using the CoreModule/SharedModule approach without knowing why. I agree, what I'm talking about is linked at the AIO page regarding CoreModule/SharedModule, but it's not that easy to get the full picture without collecting bits and pieces (https://angular.io/guide/ngmodule-faq#q-why-bad, https://angular.io/guide/singleton-services, https://angular.io/guide/ngmodule-faq#what-is-the-forroot-method ) from a few places. |
Consider reviewing this topic for v6. Now with the Consider removing the discussion and recommendation of a CoreModule entirely, especially from the Style Guide, and instead recommend using |
I was in the way to ask you this question in your PS course. happy to see your answer here. |
Remove CoreModule PR has been merged. Closing this issue. @dancancro if you still have any questions or want to share feedback, please feel free to reopen and tag me. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a ...
Current behavior
The distinction between the roles of AppModule and CoreModule is unclear.
What is the motivation / use case for changing the behavior?
If the roles are identical - provision of app-wide singletons - then there ought not be two of these and CoreModule should be eliminated. It's just confusing. If the roles are different, the distinction
should be made perfectly clear. From my cursory survey on gitter, it seems that CoreModule
serves only to keep AppModule from getting too big, but this purpose is not at all stated in the Angular docs. If this is in fact its intended and only unique purpose, then it should be called something like "KeepAppModuleFromGettingTooBigModule". "CoreModule" implies that its constituent classes serve a core role that is different from the role of those in the AppModule.
The text was updated successfully, but these errors were encountered: