How it works...

We can see the different values of Guids.

Request 1 :

Request 2:

The conclusion is the following:

  • Transient: Objects are always different; a new instance is provided to every controller and every service
  • Scoped: Objects are the same within a request, but different across different requests
  • Singleton: Objects are the same for every object and every request
  • Instance: Objects are the same for every object and every request, and are the exact instance which were specified in the code

Get ASP.NET Core MVC 2.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.