F
F
FairyFox57002020-03-24 09:25:08
ASP.NET
FairyFox5700, 2020-03-24 09:25:08

How to figure out which service with which life cycle should be applied?

I have IPersonRepository repository services etc. Also a container for storing all instances in memory (an in-memory container in the form of an IList).
There is also a service that generates a pin code and a service that calculates the amount of money on all user accounts and uses the user's repository as an argument in the constructor.
How to determine which of these services will have which life cycle (Scoped, Singltone or Transient).
I know the definitions for these cycles, but I don’t understand which one can or cannot be used.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2020-03-24
@FairyFox5700

If it is necessary that there is always one instance - singleton.
If it is necessary that there is one instance within the request (for example, in the case of DbContext in EntityFramework), then Scoped.
Otherwise, transient.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question