Description
Questions
- Is it recommended to import
CommonModule
andFormsModule
inSharedModule
orCoreModule
?
In the documentation, both are OK.
Style 04-10 (Shared feature module)
Do import all modules required by the assets in the SharedModule; for example, CommonModule and FormsModule.
Style 04-11 (Core feature module)
Do import all modules required by the assets in the CoreModule (e.g. CommonModule and FormsModule).
--
- Are you suggesting to import
CoreModule
into rootAppModule
, so that when a lazy loaded module imports theCodeModule
, it will get the intended app-wide singleton and not a new instance?
In the documentation, it suggests to import CoreModule
into the root AppModule
, but yet the subsequent lines mentioned that lazy importing CoreModule
will return a new instance.
Style 04-11 (Core feature module)
Why? CoreModule will contain singleton services. When a lazy loaded module imports these, it will get a new instance and not the intended app-wide singleton.
--
- Are services supposed to be in
CoreModule
? If not, what's the recommendation?
Based on the documentation, I thought services are supposed to be in CoreModule, but the last sentence of style 04-11 says otherwise.
Style 04-11 (Core feature module)
Why? You want the entire app to use the one, singleton instance. You don't want each module to have its own separate instance of singleton services. Yet there is a real danger of that happening accidentally if the CoreModule provides a service.