I come from a Java background and when I have designed APIs I have always done all database transactions in repository classes, called on their functionality in my service classes where I do my heavy calculations try/catch and finally presented the results to the controller that checks what kind of result it is and passes it on.
Now I'm building a API in ASP.NET Core 6 and all documentation I read seems to show/say that all DB transactions are made inside the service classes it self. For example here:
For reference I'm also using a MongoDB. But this feels strange to Initiate a DB connection in each service class and then do DB transactions there as well. Is this correct?
Can I follow the pattern on this page?