Blazor Tutorial C# - Part 3 | Blazor Dependency Injection | Singleton Service | Transient Service

preview_player
Показать описание
Blazor Tutorial C# - Part 3 is a Blazor Dependency Injection tutorial video in which we explains about the Singleton Service and Transient Service. In this video we'll see how to implement dependency injection in #Blazor.

Below is the Blazor Tutorial Playlist Link:

What is Dependency Injection?
Dependency Injection is a mechanism in which an object receives other objects that it depends on, called dependencies. Typically, the receiving object is called a client and the passed-in (injected) object is called a service.

Understanding the life cycle of Dependency Injection (DI) is very important. As we know, Dependency injection (DI) is a technique for achieving loose coupling between objects and their collaborators, or dependencies.

To implement dependency injection, we need to configure a Dependency Injection container with classes that is participating in DI. DI Container has to decide whether to return a new instance of the service or provide an existing instance. The lifetime of the service depends on when the dependency is instantiated and how long it lives. And lifetime depends on how we have registered those services.

What is Scoped Service (Dependency Injection Scoped)?
A new scope is created for each request. That means all the Scoped services for a given request are resolved from the same container, so the same instance of a Scoped service is used everywhere for a given request. At the end of the request, the scope is disposed, along with all the resolved services.

What is Singleton Service (Blazor Singleton Service)?
Singleton is a design pattern in which there will be a single copy of your object inside server memory, which will be shared among all the requests (http/client). So, when you register any dependency in your application as a Singleton, then you will get a single copy of an object per server/node/instance.

What is Transient Service (Blazor Transient Service)?
Transient services are created every time they are injected or requested. That means a new instance will get created each time when the service is requested.

Video Content
0:00 - Intro
2:57 - Singleton Service
19:16 - Transient Service
21:59 - Dependency Injection in Partial Class
25:43 - Service with Interface

You can reach us at Social Media:
Рекомендации по теме