Singleton Design Pattern in C# - Do it THAT way

SdĂ­let
VloĆŸit
  • čas pƙidĂĄn 23. 11. 2022
  • 🚀 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

Komentáƙe • 30

  • @tutorialsEUC
    @tutorialsEUC  Pƙed 10 měsĂ­ci

    🚀 C# Progress Academy - Become a job-ready C# and Angular web developer to land your dream developer role: bit.ly/45vbPUg

  • @superkfc5410
    @superkfc5410 Pƙed rokem +4

    This is the best Singleton tutorial i've come across. Great stuff!

  • @rodolfoa.calvojaubert9953
    @rodolfoa.calvojaubert9953 Pƙed 7 měsĂ­ci +5

    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_221 Pƙed 3 měsĂ­ci

    Excellent demonstration

  • @mateociotti3564
    @mateociotti3564 Pƙed 7 měsĂ­ci

    Helped a lot, thanks

  • @777grw
    @777grw Pƙed 6 měsĂ­ci

    Simple and precise

  • @abyandev8571
    @abyandev8571 Pƙed rokem +4

    easy to follow. Best Tutorial ❀

  • @sefatergbashi
    @sefatergbashi Pƙed rokem

    Thank you!

  • @rktmimob
    @rktmimob Pƙed 6 měsĂ­ci

    explained very easy way 😊

  • @saecula2391
    @saecula2391 Pƙed rokem +1

    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 Pƙed rokem

    Nice! Great job đŸ‘đŸ»đŸ‘đŸ»đŸ‘đŸ»

  • @NivedyaSusil
    @NivedyaSusil Pƙed měsĂ­cem

    Thanks !
    Pls do videos on other design patterns as well

  • @MarinaMarina-fr8ex
    @MarinaMarina-fr8ex Pƙed 5 měsĂ­ci

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

  • @iamnoob7593
    @iamnoob7593 Pƙed rokem

    Superb

  • @user-dt1cv6hs2g
    @user-dt1cv6hs2g Pƙed 8 měsĂ­ci

    good one

  • @sumitvishwakarma56
    @sumitvishwakarma56 Pƙed 18 dny

    What if we have a distributed environment , multiple instance of this service would be running, how do we prevent multiple instances then?

  • @jhonnidarshan3094
    @jhonnidarshan3094 Pƙed rokem

    Nice tutorial

  • @rhtservicestech
    @rhtservicestech Pƙed 9 měsĂ­ci

    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 Pƙed 8 měsĂ­ci +1

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

  • @JohnEBoldt
    @JohnEBoldt Pƙed 28 dny

    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 Pƙed rokem

    @8:40 is the critical section of this video thread.

  • @jithumuraleedharan5231
    @jithumuraleedharan5231 Pƙed rokem

    ❀

  • @Matthew-sy4lj
    @Matthew-sy4lj Pƙed rokem +1

    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  Pƙed rokem

      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 Pƙed 3 měsĂ­ci

    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.