Comments on: C# Design Patterns – Singleton https://code-maze.com/singleton/ Learn. Code. Succeed. Sat, 14 May 2022 07:59:14 +0000 hourly 1 https://wordpress.org/?v=6.7.5 By: Hajimalang https://code-maze.com/singleton/#comment-5652 Sat, 14 May 2022 07:59:14 +0000 https://code-maze.com/?p=47488#comment-5652 In reply to Marinko Spasojević.

Pls reply to https://code-maze.com/singleton/#comment-5399

]]>
By: Hajimalang https://code-maze.com/singleton/#comment-5651 Sat, 14 May 2022 07:57:37 +0000 https://code-maze.com/?p=47488#comment-5651 In reply to Hajimalang.

Give solution to this

]]>
By: Hajimalang https://code-maze.com/singleton/#comment-5399 Sat, 02 Apr 2022 09:02:12 +0000 https://code-maze.com/?p=47488#comment-5399 Hi,

It’s very helpful for me. I am a little confused. We used the singleton pattern for getting system configured data from DB. But it will be changed in the Admin configuration (may be active/inactive by admin).

eg. We have configuration ‘Turn on Send Message’.

We have to get this globally throughout application. It’s possible through singleton pattern

]]>
By: Marinko Spasojević https://code-maze.com/singleton/#comment-1447 Sun, 01 Sep 2019 06:11:21 +0000 https://code-maze.com/?p=47488#comment-1447 In reply to Jordi Armangué.

Thank you very much for this suggestion. I have fixed the article. I have been changing the name of the Singleton class and forgot to change the same in the Program.cs. For some reason your comment was considered as spam (I don’t know why) so I just saw it in the admin panel. Best regards,and thank you one more time.

]]>
By: Jordi Armangué https://code-maze.com/singleton/#comment-1446 Fri, 30 Aug 2019 12:27:21 +0000 https://code-maze.com/?p=47488#comment-1446 Hi Marinko, I suggest you to update the following snippet in your article:

class Program
{
static void Main(string[] args)
{
var db = SingletonDatabase.Instance;
var db2 = SingletonDatabase.Instance;
var db3 = SingletonDatabase.Instance;
var db4 = SingletonDatabase.Instance;
}
}

in order to use the same class name than in the previous steps “SingletonDataContainer” instead of “SingletonDatabase”. It’s outdated and it has been confusing to me.

Thanks for the article!

]]>
By: Dan https://code-maze.com/singleton/#comment-739 Tue, 26 Feb 2019 06:14:05 +0000 https://code-maze.com/?p=47488#comment-739 The problem with Singletons is, they are so easy to use that inexperienced programmers overuse them as ‘global class’.
And as you haven’t written any line about unit testing…
Don’t use Singletons (or only carefully) when you’re willing to write UnitTests, mocking gets hard. Use dependency injection of an instance rather than getInstance.

Dan

]]>
By: Marinko https://code-maze.com/singleton/#comment-740 Tue, 26 Feb 2019 02:13:27 +0000 https://code-maze.com/?p=47488#comment-740 In reply to Dan.

Hello Dan. Yes, this is a problem with this pattern, but people use it and even .NET Core provides you with a possibility to register service as a singleton through the AddSingleton method (but as you said, then it could be used width Dependency Injection). Anyhow, I agree with you that it should be used with caution. Thank you for your comment, it is going to be helpful for our readers for sure.

]]>