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

  Рет қаралды 17,130

Coding Droplets

Coding Droplets

Күн бұрын

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:
• Blazor Tutorial - Begi...
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:
Facebook: / codingdroplets
Twitter: / codingdroplets
Instagram: / codingdroplets
Github: github.com/codingdroplets/

Пікірлер: 56
@rosarioalonzo6709
@rosarioalonzo6709 8 ай бұрын
Crazy a tutorial of this quality is for free, thanks a lot and keep up the good work!
@CodingDroplets
@CodingDroplets 8 ай бұрын
Thank you so much for your kind words! I'm delighted that you found the tutorial valuable.
@dungle-wh9td
@dungle-wh9td Жыл бұрын
You are the Champ sir! much appreciate! I did not get tired watching it :) lol, and I am going to the next one now.
@CodingDroplets
@CodingDroplets Жыл бұрын
Thank you so much for your kind words! I'm glad to hear that you found the video helpful and enjoyable to watch. I'm always happy to hear from viewers like you who find value in my content.
@ElCidPhysics90
@ElCidPhysics90 Жыл бұрын
Very nice. This is perhaps the best explanation of the use of interfaces I’ve seen.
@CodingDroplets
@CodingDroplets Жыл бұрын
Wow, thanks!
@ElCidPhysics90
@ElCidPhysics90 Жыл бұрын
@@CodingDroplets you’re welcome
@antuelectronica1154
@antuelectronica1154 Жыл бұрын
Excelente explicacion con el ejemplo sobre Inyeccion de dependencia y tipos de servicios.
@CodingDroplets
@CodingDroplets Жыл бұрын
Thank you for your comment! I'm glad to hear that you found video helpful and informative. If you have any further questions or topics you'd like me to cover in future videos, please let me know. Thanks again for your support!
@user-xt9vl9kx5g
@user-xt9vl9kx5g Жыл бұрын
Really!~ Thank you very much!~ You my light!~
@CodingDroplets
@CodingDroplets Жыл бұрын
You're most welcome. Glad to know you liked it.
@vittoriomorellini1939
@vittoriomorellini1939 Жыл бұрын
Very good explanation of DI pattern
@CodingDroplets
@CodingDroplets Жыл бұрын
Thank you for your comment! I'm glad to hear that you found the explanation of the Dependency Injection (DI) pattern in the tutorial helpful.
@BarthObiefuna
@BarthObiefuna Жыл бұрын
Good content. Good details. Excellent!
@CodingDroplets
@CodingDroplets Жыл бұрын
Glad you liked it!
@nlomdy
@nlomdy Жыл бұрын
Thank you!
@CodingDroplets
@CodingDroplets Жыл бұрын
You're welcome!
@rasikasamith
@rasikasamith 9 ай бұрын
Really good video. Thanks.
@CodingDroplets
@CodingDroplets 8 ай бұрын
Thank you so much for your positive feedback!
@pepeluus1153
@pepeluus1153 3 ай бұрын
thank you for the guide, its very helpfull
@CodingDroplets
@CodingDroplets 2 ай бұрын
Glad to hear that!
@AndreiHetel
@AndreiHetel Жыл бұрын
Very well explained, thank you.
@CodingDroplets
@CodingDroplets Жыл бұрын
Thank you so much for your kind comment! I'm really glad to hear that you found my explanation of dependency injection in .NET Blazor to be helpful.
@ahmedeleddrisy8438
@ahmedeleddrisy8438 2 жыл бұрын
thank you very much
@CodingDroplets
@CodingDroplets 2 жыл бұрын
Most welcome
@ZombeeDevil
@ZombeeDevil Жыл бұрын
very good content
@CodingDroplets
@CodingDroplets Жыл бұрын
Thank You!
@Fifwayte
@Fifwayte 4 ай бұрын
Merci messire
@CodingDroplets
@CodingDroplets 4 ай бұрын
You are welcome!
@harran9962
@harran9962 Жыл бұрын
Very good explanation of DI, singleton, transient services. Also as a note I think scoped are like singletons but for client requests. Exists once per client request and is shared rather than once per application, this way they are not shared between clients in some way. Though if this is wrong then plz let me know.
@CodingDroplets
@CodingDroplets Жыл бұрын
Thank you for watching the tutorial and for your positive feedback! I'm glad to hear that you found the explanation of dependency injection, singleton, and transient services to be helpful. Regarding your note about scoped services, you are absolutely correct! Scoped services in Blazor are created once per client request and are shared within that specific request. This ensures that each client receives its own instance of the scoped service, avoiding sharing between different clients. Your understanding is accurate, and it's great to see you connecting the concepts.
@shankaranarayanan_HighQ
@shankaranarayanan_HighQ 8 ай бұрын
How can I implement global variables. Lets say I'm setting a value to a variable which will be used across multiple places, like checkin - checkout date in hotel reservation app. once after publishing it to IIS. if I used singleton, other users also have the same value, if I use scoped or transient value gets lost on page refresh. Which one should I use?
@oktjona
@oktjona Жыл бұрын
i appreciate you efforts .can you do for blazor net maui too blazor hybrid
@CodingDroplets
@CodingDroplets Жыл бұрын
Thank you for watching the video and leaving your feedback. I'm glad that you found the tutorial helpful and informative. As for your request to cover Blazor in .NET MAUI, I'm happy to let you know that I have a .NET MAUI tutorial series available on our KZbin channel. kzbin.info/aero/PLzewa6pjbr3KKuUTp8ivXjcR4rvFvyoNw While I have currently only covered .NET MAUI App tutorials, I do plan to include Blazor videos in the series soon. Thank you for your interest and support, and I hope you'll find my upcoming videos on Blazor in .NET MAUI to be just as helpful.
@oktjona
@oktjona Жыл бұрын
Thankyou much love from uganda
@CodingDroplets
@CodingDroplets Жыл бұрын
Thanks a lot!
@Gabriel-kl6bt
@Gabriel-kl6bt 2 жыл бұрын
I prefer to use @inject within the razor file. I think having too many [Inject], summing with [Parameter], unnecessarily pollutes the file.
@CodingDroplets
@CodingDroplets 2 жыл бұрын
@inject is my favourite option as well.
@shailydesai7097
@shailydesai7097 8 ай бұрын
Do you have any videos on using managing sessions and Cache with Blazor server in .NET Core?
@CodingDroplets
@CodingDroplets 8 ай бұрын
Thank you for your question! While I don't have a video specifically on managing sessions and cache with Blazor Server in .NET Core at the moment, I'm planning to create one soon. It's a valuable topic, and I appreciate your interest.
@shailydesai7097
@shailydesai7097 8 ай бұрын
@@CodingDroplets Sounds great! Will looking forward for it.
@noahyannis2465
@noahyannis2465 2 жыл бұрын
What is the difference between contacts = contactService.ContactList and GetContacts()?
@CodingDroplets
@CodingDroplets 2 жыл бұрын
In the video we've changed the ContactList from public to private. You won't be able to fetch the contacts using contactService.ContactList if it is a private variable. A private variable can be accessed only within the class. Hence we've implemented a GetContacts method to fetch the data in the razor components.
@noahyannis2465
@noahyannis2465 2 жыл бұрын
@@CodingDroplets Thanks. I've been learning C# for 9 months and now I'm trying to build a Blazor application through your tutorials. Most of the time I feel really dumb and that I should know how to do certain things by now. It really sucks, but I won't give up. Did you feel the same when you started learning and if so, how did you deal with it?
@CodingDroplets
@CodingDroplets 2 жыл бұрын
Hello Noah Yannis. Really appreciate you efforts to learn C# development. Initially it will be hard to understand if you don't have experience in Object Oriented Programming. But gradually the things will become more easier. Don't give up. You can reach me for any doubts. I'll answer as soon as possible. Once you master any of the Object Oriented Programming language like C#, Java etc. Other languages will be easier for you to understand.
@mswalsh68
@mswalsh68 3 ай бұрын
I have copied everything like you have, but when I click the button to add the contact, no contacts get added, and it still shows "No Contacts to Display"
@pepeluus1153
@pepeluus1153 3 ай бұрын
try to write @rendermode InteractiveServer in top of your blazor page, to enable the user interaction. its work for me
@RayanMADAO
@RayanMADAO Жыл бұрын
How do I clear singleton service data every once in a while
@CodingDroplets
@CodingDroplets Жыл бұрын
Can you elaborate your requirement?
@RayanMADAO
@RayanMADAO Жыл бұрын
@@CodingDroplets If I have a list of objects stored as a singleton, kinda like an in memory database, how do I clear the list of objects like every 24 hours without restarting the application. Or do I just restart the application and that's it
@CodingDroplets
@CodingDroplets Жыл бұрын
For these scenarios. I prefer using distributed caching with Redis. We can assign the data expiration as well. Please check the below video. kzbin.info/www/bejne/anPVXoSkd9Rpj9k You can also use IMemoryCache if you just need to access the data in a single application. learn.microsoft.com/en-us/aspnet/core/performance/caching/memory
@AbhilashYadavSanghsevak
@AbhilashYadavSanghsevak 2 жыл бұрын
Waht about add scoped?
@CodingDroplets
@CodingDroplets 2 жыл бұрын
The Blazor Server hosting model supports the Scoped lifetime across HTTP requests but not across SignalR connection/circuit messages among components that are loaded on the client.
@khiemphamngoc3227
@khiemphamngoc3227 Жыл бұрын
@@CodingDroplets can you explain detail addscope.
@woife4069
@woife4069 Жыл бұрын
you should not use .Count == 0 but instead use .Any (negated) , because count iterates the full List
@CodingDroplets
@CodingDroplets Жыл бұрын
Yes.. Thank You !
Dependency Injection in .NET Core (.NET 6)
1:00:32
IAmTimCorey
Рет қаралды 181 М.
Эффект Карбонаро и бесконечное пиво
01:00
История одного вокалиста
Рет қаралды 6 МЛН
MOM TURNED THE NOODLES PINK😱
00:31
JULI_PROETO
Рет қаралды 27 МЛН
Como ela fez isso? 😲
00:12
Los Wagners
Рет қаралды 34 МЛН
ASP.NET Core - Service Scope - Singleton vs Scoped vs Transient
10:11
Strongest man in Norway tries Insane fitness test
18:57
Magnus Midtbø
Рет қаралды 1,2 МЛН
What is Dependency Injection? | Why | Spring
8:17
Telusko
Рет қаралды 679 М.
Dependency Injection
45:17
Microsoft Visual Studio
Рет қаралды 146 М.
What is Dependency Injection in .NET?
7:31
DotNetMastery
Рет қаралды 20 М.
Learn Dependency Injection and Write Better Code
21:52
Amigoscode
Рет қаралды 166 М.