Загрузка страницы

How to Use Dependency Injection in ASP.NET Core

💻 Download the Source Code 💻
https://www.roundthecode.com/asp-net-core-examples/dependency-injection-in-asp-net-core?utm_source=youtube&utm_medium=referral&utm_campaign=How%20to%20Use%20Dependency%20Injection%20in%20ASP.NET%20Core

ASP.NET Core supports the dependency injection design pattern and we will show you how to use it.

We will use an ASP.NET Core MVC application and will create a service for each of the service lifetimes in DI: Singleton, Scoped and Transient.

In addition, these services will be registered as part of dependency injection, and set the current time as a property when these services are initialised.

Afterwards, we will create a controller, and inject each service into the controller.

An action will be set up in the controller using the inject services, and output the initialised time value into a razor view. This is so we can see the differences as to when each service is initialised, and we can see how the different service lifetimes work.

Next, we will inject the same values into a view to see the differences between the values of the injected services in the controller and in the view.

Errors can often occur when using dependency injection, and we will show you the reasons behind the following common errors:

► A circular dependency was detected for the service of type {type}.
► Cannot consume scoped service '{type}' from singleton '{type}'
► No service for type '{type}' has been registered.

Other areas we will tackle include other ways of implementing DI, how to explicitly define a scope (handy for background tasks), and how to register a service in DI using a delegate.

💬 Got an ASP.NET Core coding issue? Join our Discord Server and ask the community for help 💬
https://www.roundthecode.com/discord

► Chapters
0:00 Introduction
0:54 Join our Discord Server
1:03 How Dependency Injection Works in ASP.NET Core MVC
2:03 Create the Web Application
3:28 Implement Dependency Injection in ASP.NET Core
18:04 Another Way of Implementing Dependency Injection
21:26 Common Errors when Using Dependency Injection
24:14 Explicitly Define a Scope in Dependency Injection
29:55 Use a Delegate to Register a Service
31:06 Other Dependency Injection Software

► More Information: https://www.roundthecode.com/dotnet/how-to-implement-dependency-injection-in-asp-net-core?utm_source=youtube&utm_medium=referral&utm_campaign=How%20to%20Use%20Dependency%20Injection%20in%20ASP.NET%20Core

#aspnetcore #dependencyinjection #di

Видео How to Use Dependency Injection in ASP.NET Core канала Round The Code
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
26 февраля 2021 г. 11:00:02
00:31:47
Яндекс.Метрика