0

Reading the accepted answer for this question it says:

"Transient - entity framework contexts can not be shared by 2 threads, so if you wanted to do any asynchronous work. You would use a transient so that a new instance of the context is created for every component. Otherwise you would have to wait for the scoped component to finish before it moves onto the next."

Does this mean that AddSingleton and AddScoped block during async calls?

Sam Axe
  • 33,313
  • 9
  • 55
  • 89
TomDane
  • 1,010
  • 10
  • 25
  • 6
    object construction is a sync process. specifically whats wrong? – Daniel A. White Oct 17 '19 at 19:02
  • @DanielA.White nothing is wrong. I am just trying to understand the pros and cons of AddTransient vs AddSingleton vs AddScoped. That accepted answer in the quote made it sound like AddScoped was blocking during multiple async calls. – TomDane Oct 17 '19 at 19:05
  • 2
    thats more about thread safety of the components registered. – Daniel A. White Oct 17 '19 at 19:06

1 Answers1

0

Transient: : will use a new instance for each time the class or the service being called through the same HttpRequest while processing it in the pipieline.

Scoped: will use the same instance through all the pipeline processing for a single HttpRequest.

Singelton: Will use the same instance for all the httprequests for all the HttpRequests for all the users who navigate your site.

Absi
  • 30
  • 3