Questions tagged [singleton]
The singleton is a design pattern aiming to ensure that only a single instance of a class can be created and used.
144 questions
0 votes
1 answer
588 views
Global Variables State Management
Background: I am working in a Java environment using Spring Boot, where I often encounter scenarios where global variable state management is critical, especially within singleton services. I have ...
0 votes
2 answers
814 views
Is it considered a code smell to not delete static pointers of a singleton?
I have a singleton that needs to be initialized at the start of the program and it will live on until the end of the program. As is usual in this pattern, a function initializing the singleton creates ...
1 vote
4 answers
1k views
Should I use a singleton to represent the application as a whole?
I make sure when designing software/firmware to make heavy use of dependency injection so that different pieces of the application are not directly coupled to one another. This also allows me to (...
1 vote
2 answers
524 views
Using class attributes as globals in Python - is there a catch?
I have found myself in the habit of using code like this. class glb: "just for holding globals" args = None # from argparse conf = None # from configparser def main(): ......
-1 votes
3 answers
965 views
Would Injecting dependencies in C# as default parameters be a bad practice?
Given the (old) debate over whether Singletons are overused/abused/are worth it - would it be a bad idea to inject the dependencies as default parameters? In this way, we could get rid of defining ...
-2 votes
3 answers
1k views
Singleton as Interface for testability via dependancy injection
It can be found in many advices on topic that having Singletons is an anti-pattern. Especially for cases of testability. Can someone please advice/critique on this way (please see code below) of ...
2 votes
0 answers
349 views
Dependency injection in .NET Core 3.x Worker Services: Why so hard to consume Transient services now?
I have a Repository service that should be Transient. It is used in many applications. I have a new application that's a Console App, and current guidance suggests implementing my business logic in ...
2 votes
2 answers
1k views
Is it right way to make Window to Singleton and call Visibility and Shutdown() methods directly in WPF?
There is a parent window that is the basis of the program, and there are several sub windows under it. Editor is one of the sub window and I'm making it. The code is as follows: // This is Code-Behind ...