Hello,
I noticed in the AppCommonModule that you use the forRoot() method to provide 2 services. Also, in the providers array of the module you provide 2 other services.
My question is why not move them all to forRoot()? Why separating them?
Because AppCommonModule would be imported in every new Feature Module, so Angular would create more than one instance of the DateTimeService and AppLocalizationService. In a time, they could be singleton also and added with forRoot()?
Thanks
7 Answer(s)
-
0
Any idea?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
hi,
Our development team decides architecture design.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
I already know that and that's why I am asking to gain some knowledge.
Maybe someone from the development team should answer this thread.
Thanks
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
In fact, this might cause problems having multiple instances of the same service, in different levels of the injector (when using lazy loading).
if possible to ask someone from dev team to comment on this here.
Thanks
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @bilalhaidar,
As I remember, it was offered by ngx-bootstrap team. Probably for using same (singleton) service for entire app.
Thanks.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Well true, it is a convention to use forRoot and forChild. But my question why keep 2 services out of the forRoot? There will be many instances at different levels (Modules and lazy loaded modules). Why not put them all in forRoot to maintain a singleton service?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @bilalhaidar,
Singleton instances are not good, especially for SPAs. It is hard to manage singleton instances. I don't know why ngx-bootsrap offers this but it is better to use transient services if possible.
If you need more information on this topic, I suggest you to search it on the web :).
Thanks.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)