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


Buy Me A Coffee

Found this article helpful? Please consider supporting!

Ram
Ram

I'm a full-stack developer and a software enthusiast who likes to play around with cloud and tech stack out of curiosity. You can connect with me on Medium, Twitter or LinkedIn.

Leave a Reply

Your email address will not be published. Required fields are marked *