Тёмный

Singleton Design Pattern in C# - Do it THAT way 

Подписаться
Просмотров 23 тыс.
% 742

🚀 C# Progress Academy - Become a job-ready C# and Angular web developer to land your dream developer role: bit.ly/45vbPUg
🏃‍♂️ Learn HOW TO work with SINGLETONS in C# with these easy steps!
We'll make sure to make a Developer out of you in no time!
So, what is C#?
C# (pronounced "See Sharp") is a modern, object-oriented, and type-safe programming language. C# enables developers to build many types of secure and robust applications that run in .NET. C# has its roots in the C family of languages and will be immediately familiar to C, C++, Java, and JavaScript programmers. This tour provides an overview of the major components of the language in C# 8 and earlier. If you want to explore the language through interactive examples, try the introduction to C# tutorials.
And what about Singletons?
In software engineering, the singleton pattern is a software design pattern that restricts the instantiation of a class to a singular instance. One of the well-known "Gang of Four" design patterns, which describe how to solve recurring problems in object-oriented software, the pattern is useful when exactly one object is needed to coordinate actions across a system.
More specifically, the singleton pattern allows objects to:
Ensure they only have one instance
Provide easy access to that instance
Control their instantiation (for example, hiding the constructors of a class)
To learn more, make sure to watch the video, and we promise you that you'll become a C# developer in no time! Have fun!
#csharp #dotnet #coding #tutorial #learn #microsoft #net #singleton #pattern #designpatterns
TAGS
dotnet,csharp,dotnet core,.net core tutorial,.net core,.net,c#,Tutorials,Tutorial,Programming,Course,Learn,Step by step,guide,programmer,core,code,c sharp,sharp,net6,6.0,.net framework,programming,visual studio,programming for beginners,coding,how to code,dot net,c# programming,tim corey,software development,singleton,gang of four,singleton design pattern,design pattern,design patterns,data structures,java,dynamic programming,singleton in c#,pattern
tutorialsEU offers you free video tutorials about programming and development for complete beginners up to experienced programmers.
This includes C#, Unity, Python, Android, Kotlin, Machine Learning, etc.
Stay tuned and subscribe to tutorialsEU: goo.gl/rBFh3x
Android: ru-vid.com/show-UCjHtatblxvHvtj2rkqlkk8Q
C#: ru-vid.com/show-UCqCnjtxdlG9qEgFJIUeLJNg
Unity: ru-vid.com/show-UCajMHiOEuARZm6t2byQRtIA
Facebook: TutorialsEU-109380204093233
LinkedIn: www.linkedin.com/company/tutorialseu
Discord: discord.gg/zwbrpCNB2M

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

 

24 ноя 2022

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 31   
@tutorialsEUC
@tutorialsEUC 10 месяцев назад
🚀 C# Progress Academy - Become a job-ready C# and Angular web developer to land your dream developer role: bit.ly/45vbPUg
@superkfc5410
@superkfc5410 Год назад
This is the best Singleton tutorial i've come across. Great stuff!
@rodolfoa.calvojaubert9953
@rodolfoa.calvojaubert9953 8 месяцев назад
Nice tut, but I must say that it does not explain when and why I should use such pattern, I think it would nice to have something like that but more orientated to a real scenarios because this is too simple
@mateociotti3564
@mateociotti3564 8 месяцев назад
Helped a lot, thanks
@777grw
@777grw 7 месяцев назад
Simple and precise
@Special_221
@Special_221 4 месяца назад
Excellent demonstration
@sefatergbashi
@sefatergbashi Год назад
Thank you!
@abyandev8571
@abyandev8571 Год назад
easy to follow. Best Tutorial ❤
@tutorialsEUC
@tutorialsEUC Год назад
Glad you think so!
@rktmimob
@rktmimob 7 месяцев назад
explained very easy way 😊
@saecula2391
@saecula2391 Год назад
sehr schön erklärt @ 08:42 .. lock gab es auch schon in delphi 5, eine sehr nützliche Funktion um gleichzeitige threads doch noch unter Kontrolle zu bringen *g
@NivedyaSusil
@NivedyaSusil Месяц назад
Thanks ! Pls do videos on other design patterns as well
@MarinaMarina-fr8ex
@MarinaMarina-fr8ex 6 месяцев назад
This is great tutorial. Can you please add more videos for other design patterns like strategy, observer, facade etc?
@FranciscoAlvino
@FranciscoAlvino Год назад
Nice! Great job 👏🏻👏🏻👏🏻
@tutorialsEUC
@tutorialsEUC Год назад
Thanks! 😊
@iamnoob7593
@iamnoob7593 Год назад
Superb
@bhaskerreddy88
@bhaskerreddy88 18 дней назад
I have one dought. What is the use of sealed keyword when the constructer is already private?
@user-dt1cv6hs2g
@user-dt1cv6hs2g 9 месяцев назад
good one
@sumitvishwakarma56
@sumitvishwakarma56 Месяц назад
What if we have a distributed environment , multiple instance of this service would be running, how do we prevent multiple instances then?
@jhonnidarshan3094
@jhonnidarshan3094 Год назад
Nice tutorial
@tutorialsEUC
@tutorialsEUC Год назад
Thank you! Cheers!
@JohnEBoldt
@JohnEBoldt Месяц назад
How about this approach? namespace SingletonConsole { public sealed class UploadService { private static UploadService _uploadService; private UploadService() { } static UploadService() { _uploadService = new UploadService(); } public static UploadService Instance() { return _uploadService; } } } Static constructors in C# are thread safe, so this will guarantee that _uploadService is initiated only the first time UploadService is referenced.
@rhtservicestech
@rhtservicestech 9 месяцев назад
Wouldn't it make more sense to remove the outer check for the null instance? I say that because you now have the same condition duplicated in your code which isn't ideal or efficient.
@alieninoy5654
@alieninoy5654 9 месяцев назад
If the outer check is removed, the application will acquire a lock every time the instance is requested, impacting performance.
@jaycorrales5329
@jaycorrales5329 Год назад
@8:40 is the critical section of this video thread.
@jithumuraleedharan5231
@jithumuraleedharan5231 Год назад
@Matthew-sy4lj
@Matthew-sy4lj Год назад
Hi there very interesting tutorial. Unfortunately though I'm receiving two errors: 1. Program does not contain a static 'Main' method suitable for an entry point (CS5001) 2. When I try to pass values from my instance threads it says that UploadService is inaccessible due to the protect level of my class being sealed/private. I'm new to programming so I'm a bit lost at the moment as I had to create a new project/program to link it with the UploadService class. What should I do?
@tutorialsEUC
@tutorialsEUC Год назад
Hi, awesome that you try it out! Make sure that your program cotains a "static void Main" and that you create a "public class UploadService". Also set your program class itself to "public". Greets :)
@andreysemykin5879
@andreysemykin5879 3 месяца назад
Instead of manually managing a lifetime for a service, using static etc it should be done via DI container and in the real world nobody does it the way in the video.