Тёмный

IDisposable Design Pattern (.Net Core) 

DotNet Core Central
Подписаться 27 тыс.
Просмотров 11 тыс.
50% 1

In this video, I will walk through how to implement IDisposable Design Pattern.
We should use an IDisposable design pattern (or Dispose Pattern) when we need to dispose of unmanaged objects.
For implementing the IDisposable design pattern, the class which deals with unmanaged objects directly or indirectly should implement the IDisposable interface. And implement the method Dispose declared inside of the IDisposable interface.
Normally, we do not directly deal with unmanaged objects. But we deal with managed classes, which deals directly with unmanaged objects. For example, File handlers, connection string, HTTP streams, etc.
One important aspect of this pattern is that it makes easier for inherited classes to follow the IDisposable design pattern. And it is because of the implementation of an overridable Dispose method.
This pattern also suggests the use of the Finalizer method (or destructor in c#). However, if we use the Finalizer, it should be managed properly due to its performance implications. I have demonstrated the suggested implementation in the video.
Source code is available in my GitHub repository here: github.com/choudhurynirjhar/i...

Наука

Опубликовано:

 

8 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 20   
@xxx.xxx.xxx.xx1joker706
@xxx.xxx.xxx.xx1joker706 4 года назад
Great explanations. Thank you.
@DotNetCoreCentral
@DotNetCoreCentral 4 года назад
@xxx.xxx.xxx.xx1 Joker thanks
@sharatmasetty
@sharatmasetty Год назад
totally agree, clear and crisp!
@sunalharbi
@sunalharbi Год назад
Great video,, many thanks
@DotNetCoreCentral
@DotNetCoreCentral Год назад
Thank you too!
@DotnetCoreTelugu05
@DotnetCoreTelugu05 4 года назад
Cool..
@omarbousbia6916
@omarbousbia6916 2 года назад
thank you
@DotNetCoreCentral
@DotNetCoreCentral 2 года назад
@Omar Bousbia, thanks for watching!
@aj.arunkumar
@aj.arunkumar 2 года назад
awesome
@DotNetCoreCentral
@DotNetCoreCentral Год назад
Thanks
@firozzaidi5346
@firozzaidi5346 3 года назад
You have a great knowledge of concept and implementation. Please try to be a bit more elaborative as you tend to complete everything quickly. By this you be able to connect with less experienced developers.
@DotNetCoreCentral
@DotNetCoreCentral 3 года назад
@firoz zaidi, thanks for the suggestion, I will definitely keep it in mind going forward.
@firozzaidi5346
@firozzaidi5346 3 года назад
Sir, Can i ask one question? Here when dispose is called by destructor, in this case httpclient is never going to be collected by garbage collector as we are passing false as paramter. So if we dont call dispose explicitly then how that resource is going to be release? I have been thinking about it for a while.please answer if have time it will be a great help.
@DotNetCoreCentral
@DotNetCoreCentral 3 года назад
@@firozzaidi5346 since HttpClient itself is a managed (tough it internally handles unmanaged object), we will call it's Dispose method only when our classes Dispose method is being called. Otherwise, when the Finalizer (or destructor) of our class is called, the Finalizer of HttpClient will also be triggered (HttpClient has its own implementation of Finalizer). Hence it will be cleaned up. I hope it answers your question.
@firozzaidi5346
@firozzaidi5346 3 года назад
@@DotNetCoreCentral thanque sir
@firozzaidi5346
@firozzaidi5346 3 года назад
@@DotNetCoreCentral Sir, Sorry to disturb again but one last question please. How do i figure out which types are managed and which ones are not.
@aniketkhot6023
@aniketkhot6023 Год назад
why do we clean up managed resources as CLR will take care of it weather client uses "Using" or not. cant we just skip clearing of managed resources?
@ajlamkhan2067
@ajlamkhan2067 Год назад
httpclient is managed reaource, actually its wrapper class which further use unmanaged resources, so it is necessary to clean such managed/wrapper objects so that Finzalize can clean them to avoid memmory blockage or leakage.. similarly Sql Connection is wrapper class bcz it use TCP socket which is unmanaged resource so it is necessary to dispose such object so that Finalize collect them to destroy..
Далее
IEnumerable VS IQueryable (in .NET Core)
10:52
Просмотров 11 тыс.
Internals of Select and SelectMany (LINQ Internals)
15:33
🤯 #funny
00:20
Просмотров 870 тыс.
когда мучает жажда // Eva mash
00:58
Просмотров 331 тыс.
IDisposable and Finalizers
23:00
Просмотров 21 тыс.
The Dispose Pattern
16:28
Просмотров 10 тыс.
8 await async mistakes that you SHOULD avoid in .NET
21:13
IDisposable Exposed
53:48
Просмотров 3,2 тыс.
Writing C# without allocating ANY memory
19:36
Просмотров 145 тыс.