From the course: ASP.NET Core in .NET 6: Dependency Injection
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Other dependency injection configuration methods - ASP.NET Core Tutorial
From the course: ASP.NET Core in .NET 6: Dependency Injection
Other dependency injection configuration methods
- [Instructor] We've talked about the AddSingleton AddScoped and AddTransient extension methods. Let's have a look at these overloads for these methods and how we can use them to configure dependency injection in our asp.net call web application. When adding a service to the DI container we can pass in the type as a generic type into the method. This is how we did it already. Alternatively, we can pass in the type as a parameter. Whichever way we do it, we're also able to override the default behavior and run a delegate to create an instance of our service. For example, there may be many customers that have added products to their shopping cart. We need a way of defining which shopping cart belongs to which customer, one way we can do that is to pass in a unique identifier which defines which shopping cart belongs to which customer. That means we can treat each shopping cart separately, and it makes it easier to assign to a…