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
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
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
ASP.NET Core Dependency InjectionUse ASP.NET Core hosted services to run a background task(#79) Dependency Injection in Asp.net core | Asp.Net Core tutorialIntroduction to Dependency Injection in C#.NET Core Console App with Dependency Injection, Logging, and Settings.NET 5 Dependency Injection.NET Core Dependency Injection - Tips and TricksAngular Tutorial - 18 - Dependency InjectionOverview of Dependency Injection in ASP.NET CoreHow to host Asp.net core web API on IISASP.NET MVC Interview questions and answers on Dependency Injection | ASP.NET Interview QuestionsHow .NET 6 Minimal APIs has evolved ASP.NET CoreASP.Net Core Web API - Onion Architecture | Best Practices ArchitectureC# Dependency Injection Explanation in .NET CoreLAYERING in ASP.NET Core | Getting Started With ASP.NET Core Series | Dependency Inversion PrincipleHow to Read The appsettings.json Configuration File in ASP.NET CoreASP.NET Core Dependency Injection - Singleton, Scoped, and TransientASP NET Core dependency injection tutorialAdvanced Dependency Injection in .NET CoreEF Core 6 new features and changes for .NET 6