We have a mono repo and using Nx layout with /libs.
A lot of the ....service.ts (services) can be reused in multiple places. Here is the question...
These services are mostly fetches from the REST API and therefore designed to be stay singletons. Where should they be provided?
My thoughts right now is to wrap each service in an NgModule
and provide it there. Then, whatever other module wants to use that service will have to import the NgModule
.
That way, if multiple modules import it, the NgModule
with the service will only get evaluated once and the service it provides will not get re-instantiated.
On the other hand, this would make for quite an explosion in the number of files in my source tree. Is that all worth it or is there a better/more elegant way of accomplishing that?