Тёмный

Singleton Design Pattern (C#, Microservices) 

Raw Coding
Подписаться 72 тыс.
Просмотров 14 тыс.
50% 1

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

 

5 сен 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 60   
@johnviggogrnbech1089
@johnviggogrnbech1089 3 года назад
I have been using locking just like this for my caching. Just nice to see that I am actually doing it as you explain it here with locking.
@RawCoding
@RawCoding 3 года назад
As long as the lock is not on critical code path and the creation process doesn’t take too long
@ShayanFiroozi1
@ShayanFiroozi1 2 года назад
I really wonder why you have only 43K subscribers ?!!🤷‍♂️ It should be at least 1 million 👍 Very informative channel and contents. Greetings from Iran.
@RawCoding
@RawCoding 2 года назад
Share the channel maybe we’ll get there ;) thank you for the kind words
@user-lq4ws7dp5k
@user-lq4ws7dp5k 3 года назад
Thank you! That was a really great example!
@RawCoding
@RawCoding 3 года назад
Thank you for watching
@nandyad
@nandyad Год назад
This is the best example
@mohankumarsantha1770
@mohankumarsantha1770 3 года назад
I like this video, but little advice to you. Try to give a small explanation about the pattern and then start with an example that makes more sense to learners. 😊
@RawCoding
@RawCoding 3 года назад
Cheers
@thatcreole9913
@thatcreole9913 3 года назад
This is extremely well done content! Thank you.
@RawCoding
@RawCoding 3 года назад
Glad you like it
@piotrc966
@piotrc966 3 года назад
Interesting case. 'bad' version: if (!c.Contains("job_id", "job1")) { c.Write("job_id", "job1"); Console.WriteLine("Big Operation"); } when set .net core 3.1 in LinqPad generate null reference exception for : { _registry[key] = value; } Same exeption is in Visual Studio. :) but just change for: { Console.WriteLine(_registry == null); _registry[key] = value; } And it's OK.
@RawCoding
@RawCoding 3 года назад
And works for net5?
@piotrc966
@piotrc966 3 года назад
@@RawCoding Yes, in LinqPad works fine, but in Visual Studio throws: "System.InvalidOperationException: 'Operations that change non-concurrent collections must have exclusive access. " This exception seems OK, but for net 3.1 "null reference" in VS and LinqPad seems very strange - probably some bugs in .NET :).
@RawCoding
@RawCoding 3 года назад
That exception is expected because we aren’t using a concurrent dictionary. As for null I’d double check what is actually null
@user-qc6sj9th3n
@user-qc6sj9th3n 3 года назад
Good explanation of the pattern)
@RawCoding
@RawCoding 3 года назад
Cheers
@LucasMarinoElementh
@LucasMarinoElementh 3 года назад
Thanks, amazing content as always!
@RawCoding
@RawCoding 3 года назад
Thank you
@ehvlullo
@ehvlullo 3 года назад
Awesome stuff. Do you ever see reason to write your own singleton (/locking) pattern in a production environment that has a DI container in place?
@RawCoding
@RawCoding 3 года назад
No
@TheNorthRemember
@TheNorthRemember 2 года назад
greate explanation, bty whats ur headset?
@RawCoding
@RawCoding 2 года назад
It’s shit, don’t recommend - smthn Bose, not the noice cancellation ones
@rajenlenka7806
@rajenlenka7806 3 года назад
Graitude Brother...Thank you
@RawCoding
@RawCoding 3 года назад
Thank you for watching
@XpLoeRe
@XpLoeRe 3 года назад
what a fucking god.
@RawCoding
@RawCoding 3 года назад
Thank you, no god though just a nerd )
@muradazimzadadev
@muradazimzadadev 2 года назад
Great elucidation! But a problem here is that private constructor of safethread singleton class called 3 times, however it should have been called once. Anyone has any idea? ( No difference in the code)
@superpcstation
@superpcstation 3 года назад
3:28 I don't understand the down side of using a static ctor? it looks cleaner than using locks
@RawCoding
@RawCoding 3 года назад
It runs on app start, so long creation processes will cause long startup time, I know it can sound silly but some apps are REALLY BIG. Additionally it’s hard to control the flow of construction as well as lack of being able to use async.
@superpcstation
@superpcstation 3 года назад
@@RawCoding Thank you :)
@teseract7442
@teseract7442 2 года назад
If u use task, can use concurrent dictionary for same caching?
@RawCoding
@RawCoding 2 года назад
Sure
@babybob8823
@babybob8823 3 года назад
Thanks for the video!! It was great. Can we do this without static ctor and lock? Wouldn't be it thread-safe and the instance will be created only once when Create() is invoked? Correct me if I'm wrong. public class MemoryCache { private static readonly MemoryCache _instance = new MemoryCache(); private MemoryCache() {} public static MemoryCache Create() { return _instance; } }
@RawCoding
@RawCoding 3 года назад
that is fine if your creation process is that simple :)
@algarud
@algarud 3 года назад
Do Observer and Strategy :)
@RawCoding
@RawCoding 3 года назад
We’ll get there
@ShayanFiroozi1
@ShayanFiroozi1 2 года назад
#suggestion Would you please make a video about how to choose our apps architecture and design patterns with real world example ? Thank you.
@RawCoding
@RawCoding 2 года назад
It’s a hard topic to cover I’ll see what I can do
@ShayanFiroozi1
@ShayanFiroozi1 2 года назад
@@RawCoding Thank You 👍
@tomthunderforest1681
@tomthunderforest1681 3 года назад
why you didn't use lock(_instance) ? 7:37
@RawCoding
@RawCoding 3 года назад
Because instance is null and we need to instantiate it, if it’s null there’s nothing to lock. You can create an empty implement that will indicate it needs instantiation but at that point it’s too much work.
@tomthunderforest1681
@tomthunderforest1681 3 года назад
​@@RawCoding Thank you for explanation :) can't wait for next episodes. Good work !
@clearlyunwell
@clearlyunwell 3 года назад
👍🏽
@RawCoding
@RawCoding 3 года назад
)
@madd5
@madd5 3 года назад
ты работаешь программистом сам, или только ютюб?
@RawCoding
@RawCoding 3 года назад
Работаю
@wisnu7734
@wisnu7734 3 года назад
Please make video System.IO.Pipeline
@RawCoding
@RawCoding 3 года назад
I’ll do, it’s quite a niche api didn’t have to use it that much
@darkomartinovic1955
@darkomartinovic1955 4 месяца назад
What about Lazy? public sealed class Singleton { private static readonly Lazy lazy = new Lazy(() => new Singleton()); public static Singleton Instance { get { return lazy.Value; } } private Singleton() { } }
@stefanioan7569
@stefanioan7569 3 года назад
What happened to you? Where’s the beard?
@RawCoding
@RawCoding 3 года назад
🔪
@cigdemturkmen
@cigdemturkmen 2 года назад
still too advanced for me. I will come back 6 months later
@RawCoding
@RawCoding 2 года назад
No rush )
@godsonjoseph
@godsonjoseph 3 года назад
First :P
@RawCoding
@RawCoding 3 года назад
👏
Далее
Adapter/Wrapper Design Pattern (C#, Microservices)
12:05
Как дела перцы?
00:25
Просмотров 72 тыс.
ДО ВСТРЕЧИ НА РАЗГОНЕ
52:11
Просмотров 453 тыс.
Semaphore Explained C#
12:24
Просмотров 40 тыс.
Singleton Design Pattern in C# - Do it THAT way
13:15
Proxy/Ambassador Design Pattern (C#, Microservices)
13:09
Prototype Design Pattern (C#)
12:30
Просмотров 16 тыс.
"Stop Using Singletons in .NET!" | Code Cop #009
13:52
Why .NET's memory cache is kinda flawed
14:13
Просмотров 55 тыс.
5 Design Patterns That Are ACTUALLY Used By Developers
9:27
Flyweight Design Pattern (C#)
12:02
Просмотров 7 тыс.