Singleton Design Pattern in C# - Do it THAT way

🚀 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: / @tutorialseuandroid
C#: / @tutorialseuc
Unity: / @tutorialseuunity
Facebook: / tutorialseu-1093802040...
LinkedIn: / tutorialseu
Discord: / discord

Пікірлер: 30

  • @tutorialsEUC
    @tutorialsEUC9 ай бұрын

    🚀 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.calvojaubert99537 ай бұрын

    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

  • @Special_221
    @Special_2213 ай бұрын

    Excellent demonstration

  • @mateociotti3564
    @mateociotti35647 ай бұрын

    Helped a lot, thanks

  • @777grw
    @777grw6 ай бұрын

    Simple and precise

  • @abyandev8571
    @abyandev8571 Жыл бұрын

    easy to follow. Best Tutorial ❤

  • @tutorialsEUC

    @tutorialsEUC

    Жыл бұрын

    Glad you think so!

  • @sefatergbashi
    @sefatergbashi Жыл бұрын

    Thank you!

  • @rktmimob
    @rktmimob6 ай бұрын

    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

  • @FranciscoAlvino
    @FranciscoAlvino Жыл бұрын

    Nice! Great job 👏🏻👏🏻👏🏻

  • @tutorialsEUC

    @tutorialsEUC

    Жыл бұрын

    Thanks! 😊

  • @NivedyaSusil
    @NivedyaSusilАй бұрын

    Thanks ! Pls do videos on other design patterns as well

  • @MarinaMarina-fr8ex
    @MarinaMarina-fr8ex5 ай бұрын

    This is great tutorial. Can you please add more videos for other design patterns like strategy, observer, facade etc?

  • @iamnoob7593
    @iamnoob7593 Жыл бұрын

    Superb

  • @user-dt1cv6hs2g
    @user-dt1cv6hs2g8 ай бұрын

    good one

  • @sumitvishwakarma56
    @sumitvishwakarma5617 күн бұрын

    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!

  • @rhtservicestech
    @rhtservicestech9 ай бұрын

    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

    8 ай бұрын

    If the outer check is removed, the application will acquire a lock every time the instance is requested, impacting performance.

  • @JohnEBoldt
    @JohnEBoldt27 күн бұрын

    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.

  • @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
    @andreysemykin58793 ай бұрын

    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.