tagged [singleton]
How to abstract a singleton class?
How to abstract a singleton class? This is how I write my singleton classes. ``` public class MyClass { /// /// Singleton /// private static MyClass instance; /// /// Singleton access. /...
- Modified
- 25 May at 02:9
Generic Singleton<T>
Generic Singleton I have a question, is this the correct approach to make a Generic Singleton? ``` public class Singleton where T : class, new() { private static T instance = null; private S...
- Modified
- 15 Oct at 19:43
Trouble with initializing NSMutableArray in my Singleton
Trouble with initializing NSMutableArray in my Singleton I am getting a weird error, and I can't figure it out. This takes place inside of a class that is created with the singleton pattern: When I
- Modified
- 12 Nov at 12:31
Binding one class to several interfaces as singleton
Binding one class to several interfaces as singleton I have for instance 2 interfases `IInterface1` and `IInterface2`, and one implementation of these interfaces `ImplClass`. I have to be sure that ap...
- Modified
- 12 Sep at 09:3
Return same instance for multiple interfaces
Return same instance for multiple interfaces I'm registering components with the following code: ``` StandardKernel kernel = new StandardKernel(); string currentDirectory = Path.GetDirectoryName(GetTy...
Serialize a Static Class?
Serialize a Static Class? What happens if we serialize a static class? Can more than one instance of the static class be created if we serialize it? Suppose I XmlSerialize the object to a XML file, an...
- Modified
- 18 Aug at 12:21
The need for volatile modifier in double checked locking in .NET
The need for volatile modifier in double checked locking in .NET Multiple texts say that when implementing double-checked locking in .NET the field you are locking on should have volatile modifier app...
Advantage of Static class over use of Singleton
Advantage of Static class over use of Singleton ## Duplicate > [What’s wrong with singleton?](https://stackoverflow.com/questions/86654/whats-wrong-with-singleton) [Singletons: good design or a crutc...
Singleton Properties
Singleton Properties Ok, if I create a singleton class and expose the singleton object through a public static property...I understand that. But my singleton class has other properties in it. Should t...
- Modified
- 8 Mar at 21:46
How do singleton patterns work in a web context?
How do singleton patterns work in a web context? So, An object that uses the singleton pattern can only have one instance. How does this work on websites? 1. Is the singleton object unique to each cli...
- Modified
- 6 Jul at 12:52
What are drawbacks or disadvantages of singleton pattern?
What are drawbacks or disadvantages of singleton pattern? The [singleton pattern](https://en.wikipedia.org/wiki/Singleton_pattern) is a fully paid up member of the [GoF](https://en.wikipedia.org/wiki/...
- Modified
- 20 Jun at 07:56
Can I define an abstract class for all derived Singletons in this way?
Can I define an abstract class for all derived Singletons in this way? This is my abstract class which must be derived each time I want to make a [Singleton](http://msdn.microsoft.com/en-us/library/ff...
- Modified
- 19 Nov at 18:8
A generic singleton
A generic singleton What do you guys think about this for a generic singleton? ``` using System; using System.Reflection; // Use like this /* public class Highlander : Singleton { private Highlander...
ASP.NET Core initialize singleton after configuring DI
ASP.NET Core initialize singleton after configuring DI So let's say I have a singleton class instance that I register in the DI like this: And let's say the `Foo` class has a number of other dependenc...
- Modified
- 8 Jul at 22:50
Singleton by Jon Skeet clarification
Singleton by Jon Skeet clarification ``` public sealed class Singleton { Singleton() {} public static Singleton Instance { get { return Nested.instance; } } class Nested ...
- Modified
- 11 Mar at 12:41
How to create module-wide variables in Python?
How to create module-wide variables in Python? Is there a way to set up a global variable inside of a module? When I tried to do it the most obvious way as appears below, the Python interpreter said t...
How to code Jon Skeet's Singleton in C++?
How to code Jon Skeet's Singleton in C++? On Jon's [site](http://www.yoda.arachsys.com/csharp/singleton.html) he has thisvery elegantly designed singleton in C# that looks like this: ``` public sealed...
Is it a good practice to have logger as a singleton?
Is it a good practice to have logger as a singleton? I had a habit to pass logger to constructor, like: But that is quite annoying, so I've used it a property this for some time: ``` private ILogger l...
- Modified
- 13 Dec at 08:9
Disposable singleton in C#
Disposable singleton in C# I have a singleton that uses the "static readonly T Instance = new T();" pattern. However, I ran into a case where T is disposable, and actually needs to be disposed for uni...
Thread Safe C# Singleton Pattern
Thread Safe C# Singleton Pattern I have some questions regarding the the singleton pattern as documented here: [http://msdn.microsoft.com/en-us/library/ff650316.aspx](http://msdn.microsoft.com/en-us/l...
- Modified
- 9 May at 19:28
Ways to setup a Ninject singleton
Ways to setup a Ninject singleton I have a class (`MyFacade`) that I injected parameter(s) with `Ninject`: Of course, I have to setup the `Ninject` to inject the appropiate impleme
How do you choose between a singleton and an unnamed class?
How do you choose between a singleton and an unnamed class? I'd use a singleton like this: I'd use an unnamed class like this: I feel as if the Singleton pattern has no advantage over the unnamed clas...
Different ways to initialize singletons
Different ways to initialize singletons Working in C# and Java, I've seen basically one way everybody initializes singletons: Now, when I move to Objective-C for the iPhone, whenever I see code sample...
- Modified
- 28 Oct at 14:31
Singleton with parameters
Singleton with parameters I need a singleton class to be instantiated with some arguments. The way I'm doing it now is: ``` class SingletonExample { private SingletonExample mInstance; //other mem...
- Modified
- 17 Nov at 11:23
Working with singletons in .Net Remoting
Working with singletons in .Net Remoting I'm having a bit of a problem with a singleton class I'm exposing via remoting. In my server I have: ``` TcpChannel channel = new TcpChannel( Settings.Default....