Skip to main content

Posts

Showing posts with the label ASP.net Core

ASP.net Core Services Lifetime Differences Between Using AddTransient, AddScoped and AddSingleton Services

  ASP.net Core Services Lifetime Differences Between Using AddTransient, AddScoped and AddSingleton Services Overview In this blog post, I will be explaining to you the ASP.net core Service Lifetime and will be explaining to you what is the difference between them and which one can be a risk to a memory leak if used incorrectly. AddTransient, AddScoped, and AddSingleton are dependency injection services in ASP.NET Core. The differences between them are as follows below. AddTransient: A new instance of the service is created every time it is requested. AddScoped: A single instance of the service is created per request within the same scope. AddSingleton: A single instance of the service is created for the entire application lifetime. In general, it's recommended to use AddScoped for services that are stateful and AddTransient for services that are stateless or have a short lifetime. AddSingleton is usually used for services that are expensive to create or only need to be crea...

How to use Enum Data Values with .Net 6.0 Framework and Entity Framework Core 6

How to use Enum Data Values with .Net 6.0 Framework and Entity Framework Core 6 Overview An Enum (Enumeration) is a group of constants that are read-only value types. By default, the first value of the Enum variable is 0 i.e. Here we will create an Enum of Priorities type with read-only values of Highest, Normal and Low. We will set the read-only values using an integer assigning a number next to the value. By default, the integer value will start with 0. Here we will be assigning the integer value next to the Enum value such as in the below example and we will use a comma (,) to separate the item in the list of Enum(Enumeration).  We create Enum by using the Enum keyword and then using class, interface, and abstract. The reason we use an Enum is to ensure we improve our application performance and improve application readability, and maintainability, and reduces the complexity of the application hence why if you take a look at the example below of Status (NotStarted, Started, Comp...