Lifetime Scope For ASP.NET Core 8 Burgers

Mar 28, 2024

MatrixBurger

There are different lifecycles and lifetime spans to the objects managed by dependency injection containers. That was a mouthful! Dependency injection containers are classes that can represent objects as an instance and/or configure objects. So, another way to explain lifecycles is that each object (burger being ordered) will have different reactions to stimuli (the order to the waiter) given their lifecycles within a class that houses them (the diner). Now let’s explain the three different lifecycles.

Transient:

In a transient lifecycle each instance of an object will be seen as a unique individual instance even within the same request. The best way to explain this is going back to the burger. If 3 of you order 3 of the same burgers at the diner you get three burgers, well, in the transient lifecycle the object will be seen as three unique instances of the same object and return the said object three times.

The type of web applications that will benefit from objects with a transient lifestyle are:

  • E-Commerce Platforms
  • Reservation Booking Platforms
  • Gaming Platforms
  • Social Networks

Scoped:

In a scoped lifecycle each instance of an object will still only be counted once within a singular request. If all 3 people at the table orders the same burger at the same time, the waiter can’t hear all three people talking at the same time and will only bring one burger to the table. In a scoped lifecycle all duplications of objects are combined into one singular instance during the same request. For the table to get three burgers each person must order their burger (make a request) consecutively.

The type of web applications that benefit from objects with a scoped lifestyle are: 

  • Online Banking/Financial Services
  • Healthcare Applications
  • Educational Platforms
  • Customer Support/Ticketing Systems

Singleton:

In a singleton lifecycle when an object is requested multiple times only one (same) object will be returned.  If everyone in the diner ordered a burger, everyone is going to Taco Bell because the cook is only making one burger. Don’t go to Singleton restaurants, you’ll leave hungry and bloody…I know from experience.

The type of web applications that benefit from objects with a singleton lifestyle are: 

  • Database Connection Pools
  • Cache Systems
  • Logging Services
  • Configuration Management Systems

Justin.TadrosJustin Tadros is a Project Manager and Data Analyst at The Training Boss. Justin has a bachelor degree in Theater performance from Rollins College and currently pursuing his Masters in business at the University of Center Florida.  Justin is certified on Microsoft Power BI and Progress Sitefinity Sales accreditation with on going training on Python and CMS technologies.  Justin performs in theaters in Orlando, Boston, Alaska and stand up comic whenever the opportunity arises.  His passion for performing and bringing incredible customer service to any industry he approaches is second to his commitment, dedication and hard work.

Tags:

Playlist for Sitefinity on YouTube

 

Playlist for Microsoft Fabric on YouTube

 

Playlist for AI on YouTube

Copyright © 2024 The Training Boss LLC

  Developed with Sitefinity 15.1.8321 on ASP.NET 8