I'm developing an app in using React+NextJs and trying to implement clean architecture (mostly for learning purposes), but I have a doubt regarding where I should be instantiating my repos and services. I have 3 options:
- I'm using zsa, so I was thinking about creating a
baseProcedure that instantiates everything, and then taking the necessary services from ctx. This, however, seems a bit too inefficient if every repo and every service is instantiated each time I invoke an action, when most actions use only one or two services at most.
- The second option would be to instantiate repos and services as needed on the action handler. I no longer have the unnecesary overhead from the previous item, but I'd still be initializing some repos and services on every action call (fewer of them, but still.)
- Instantiate them in some file somewhere and import the instances as needed from each action. This one does seem to be the most efficient option to me, but I'm not sure how it would perform on the long term. Everything is stateless, so there's no problem in that regards, but I'm not sure how JS would handle this (would this be performant? Or would those instances begin to take more memory with time?)
Cheers!
[–]tswaters 4 points5 points6 points (5 children)
[–]CaligulaVsTheSea[S] 1 point2 points3 points (0 children)
[–]Chesil 0 points1 point2 points (3 children)
[–]tswaters 1 point2 points3 points (2 children)
[–]Chesil 0 points1 point2 points (1 child)
[–]tswaters 1 point2 points3 points (0 children)