How decide between scopes of repository in microservice

first100 81 Reputation points
2023-10-11T19:53:22.4633333+00:00

Hi,

I have a microservice in .net 6.0, that expose some REST API, and this service get through dependency injection a sql service to get data from database.

I can have this service replicated on more instances, (in kubernetes) so i can have multiple pods of this.So I have doubts if I should use singleton or scoped for instantiate sql repository.

I think that a singleton or scoped sql repository is irrelevant in my case, because in my service i have only one of this and if my service is replicated, another process is created, so that every pods have a one singleton sql repository inside and cannot be the same, because every process has own application space, and for security reasons cannot share memory.

Do you think my reasoning is correct?

Thanks very much!

Developer technologies | ASP.NET | ASP.NET Core
Developer technologies | .NET | Other
Developer technologies | C#
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.