What are service lifetimes in ASP.NET Core?

A service lifetime defines how a service instance is maintained or created by the container when requested for a new instance.

A service lifetime defines how a service instance is maintained or created by the ASP.NET Core Inversion of Control (IoC) container when a calling method or constructor requests for a new service instance. There are three types of services based on how their instance lifetime is managed:

  1. Singleton: New instance is created only once during its entire lifetime, across requests
  2. Transient: New Instance created each time a component requests for an object
  3. Scoped: New instance is created only once per request and is reused for all calls within a request

You can learn about these types in detail here – What are Service Lifetimes in ASP.NET Core Dependency Injection Explained in Detail

Default image
Sriram Mannava

I'm a full-stack developer and a software enthusiast who likes to play around with cloud and tech stack out of curiosity.

Leave a Reply