Life Cycles

Last updated

What is Life Cycles?

In ASP.NET, dependency injection (DI) lifecycles determine the lifetime of objects that are resolved through the DI container. There are several predefined lifecycle options in the Microsoft.Extensions.DependencyInjection library, including:

  • Transient: A new instance of the object is created every time it is requested.
  • Scoped: A new instance of the object is created for each request within the same scope.
  • Singleton: A single instance of the object is created and shared across the entire application.

Additionally, you can also create a custom lifecycle by implementing the Microsoft.Extensions.DependencyInjection.IServiceScopeFactory interface

Free resources to learn Life Cycles

Life Cycles: common questions

Can I learn Life Cycles in Hindi?

This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain Life Cycles in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.

Is this Life Cycles tutorial for beginners?

It is lesson 46 of 146 in the free ASP.NET Core roadmap, in stage 8, Life Cycles. If you are new to ASP.NET Core, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.

Still confused? Ask me