singleton

Ninject and Singleton

My application uses NHibernate with a session per request implementation. I have a core library that provides a thread safe singleton for getting access to the current nhibernate session. That singleton is leveraged from the web application in the BeginRequest and EndRequest events to ensure the opening and closing of the session wit...

What's Alternative to Singleton

We have a class that holds configuration information for the application. It used to be a singleton. After some architectural review, we were told to remove the singleton. We did see some benefits of not using singleton in the unit testing because we can test different configurations all at once. Without singleton, we have to pass the i...

Cocoa - Singleton object: Where to initialize member variables?

Hello people! I was wondering where is the best place to initialize members of the singleton class. I'm using Apple fundamental guide singleton implementation. Could you please pinpoint at what line the inits happen? The code is the following: static MyGizmoClass *sharedGizmoManager = nil; + (MyGizmoClass*)sharedManager { @synchr...

Why is the Borg pattern better than the Singleton pattern in Python

Why is the Borg pattern better than the Singleton pattern? I ask because I don't see them resulting in anything different. Borg: class Borg: __shared_state = {} # init internal state variables here __register = {} def __init__(self): self.__dict__ = self.__shared_state if not self.__register: self._init_default_r...

Migration solution for singletons in an OSGI environment

I'm working in a JEE Environment in which each application is in a war file of its own. In the WEB-INF/lib of each application war file there is a common jar that is shared by all applications. This common jar contains several Singletons which are accessed from many points in the code. Because of the war-file boundaries each application ...

.Net Application-wide variables

I'm fairly new to .Net... I have several queries which will execute when the application loads. I want these queries to store the data in an object (a dataset?) which is accessible throughout the application. Should I be using a singleton class? How can a User Control within my application reference public variables in the main applicati...

Why choose a static class over a singleton implementation?

The Static Vs. Singleton question has been discussed before many times in SO. However, all the answers pointed out the many advantages of a singleton. My question is - what are the advantages of a static class over a singleton? Why not simply choose a singleton every time? ...

How to implement Singleton-like EJB3.0 bean?

I need to implement a simple DAO bean, which also caches data read from the database. This DAO bean is used by stateless beans. Because EJB3.0 doesn't support singleton beans, what would be the correct way to implement such a DAO bean? Is it ok to just use static variable to keep the cache? We are using Oracle AS and not going to use c...

what happens if more than one thread tries to access singleton object

Not during instantiation, but once instantiation of singleton object is done, what will happen if two or more threads are trying to access the same singleton object? Especially in the case where the singleton object takes lot of time to process the request (say 1 min)... In this case, if for ex., 5 threads try to access the same singleto...

Singleton Vs ServiceLocator

What are the advantages and disadvantages of using a Service Locator versus a singleton? I've read that singletons are bad but I'm wondering if s Service Locator would be generally a better way of doing things. ...

How to distribute: Notification service, ASP.PAGE, Workflow

Hello, I'm developing a distributed application I have a web page (ASP.NET) to submit information. This information needs to be handled on a specific way, so I'm using Windows Workflow Foundation. Let's call this WK1 (Workflow 1). During this flow I need to notify certain users and get info from them aswell, so I choose to notify the...

Share same object instance (singleton) between processes

I can do this for a single process (single .exe) but how can I do it between processes? ...

StructureMap Open Generics and CacheBy Singleton

I have a number of repositories that inherit from a base class Repository. Currently I am registering in-memory implmentations with Structure map like this (and it's working great): ForRequestedType<Repository<Timeslot>>() .TheDefaultIsConcreteType<InMemoryRepository<Timeslot>>() .AsSingletons(); ForRequestedType<Repository<Ap...

Tag Interface for Singletons

The 'singleton-ness' of a class is an important aspect of how a class should be used. However, it usually doesn't have any explicit status in the exposed API of a class. Yes, conventional method names such as getInstance() are often used, but that's not exactly what I'm referring to here. A 'tag interface' is an interface which contains...

C# Singleton "GetInstance" Method or "Instance" Property?

From the perspective of an API end-user who needs to "get an the instance" of a Singleton class, do you prefer to "get" an the .Instance property or "call" a .GetInstance() Method? public class Bar { private Bar() { } // Do you prefer a Property? public static Bar Instance { get { return new ...

Python singleton / object instantiation

Hi, I'm learning Python and i've been trying to implement a Singleton-type class as a test. The code i have is as follows: _Singleton__instance = None class Singleton: def __init__(self): global __instance if __instance == None: self.name = "The one" __instance = self else...

Global State and Singletons Dependency injection

this is a problem i face lot of times when i am designing a new app i'll use a sample problem to explain this think i am writing simple game.so i want to hold a list of players. i have few options.. 1.use a static field in some class private static ArrayList<Player> players = new ArrayList<Integer>(); public Player getPlayer(int...

Can I make NSManagedObject into a singleton?

I have a NSManagedObject object filled with data I want to use in multiple view controllers. Can I make this object into a singleton and use it in multiple view controllers? Or should I use a different approach? ...

Unity Container: use ContainerControlledLifetimeManager by default for "Resolve" method group

Hi! How to fill TODO to make this test pass? class MyClass { } [Test] public void Singleton_by_default_test() { var parentContainer = GetUnityContainer(); var container = parentContainer.GetChildContainer(); // TODO: Add magic here (but do NOT explicitly register MyClass in container!) Assert.AreSame(containe...

Singletons via static instance in C++ -- into source or into header files?

Cheers, I ran into this chunk of code in "Programming Game AI by Example": /* ------------------ MyClass.h -------------------- */ #ifndef MY_SINGLETON #define MY_SINGLETON class MyClass { private: // member data int m_iNum; //constructor is private MyClass(){} //copy ctor and assignment should be private MyClass(const ...