singleton

The IOC "child" container / Service Locator

DISCLAIMER: I know there is debate between DI and service locator patterns. I have a question that is intended to avoid the debate. This question is for the service locator fans, who happen to think like Fowler "DI...is hard to understand...on the whole I prefer to avoid it unless I need it." For the purposes of my question, I must av...

Singleton design pattern vs Singleton beans in Spring container

As we all know we have beans as singleton by default in Spring container and if we have a web application based on Spring framework then in that case do we really need to implement Singleton design pattern to hold global data rather than just creating a bean through spring. Please bear with me if I'm not able to explain what I actually ...

EXC_BAD_ACCESS error when my view controller tries to access a singleton variable a second time

I have an app i building which is a simple naviagtion app. I do not want to load the data from my xml multiple times so I am using a singleton to load and hold the data. My first table pushes the view of the second table. This table calls the singleton and the get the array of data from there to display in the table. This all works fine...

Zend Framework - Database Table Singleton

I have found myself doing this in my code to 'cache' the work done when instantiating my Zend_Db_Table models: if (Zend_Registry::isRegistered('x_table')) { $x_table = Zend_Registry::get('x_table'); } else { $x_table = new Default_Model_DbTable_X; Zend_Registry::set('x_table', $x_table); } It bothered me that this method i...

linq2sql: singleton or using, best practices

what is the preferred practice when linq2sql using (in asp.net mvc applications): to create "singleton" for DataContext like: partial class db { static db _db = new db(global::data.Properties.Settings.Default.nanocrmConnectionString, new AttributeMappingSource()); public static db GetInstance() { return _db; } }...

Using OpenGL drawing operations in an object-oriented setting?

I've been plowing through basic shaders and whatnot for an application I'm writing, and I've been having trouble figuring out a high-level organization for the drawing calls. I'm thinking of having a singleton class which implements a number of basic drawing operations, taking data from "user" classes and passing that to the appropriate...

Static Access To Multiple Instance Variable

I have a singleton instance that is referenced throughout the project which works like a charm. It saves me the trouble from having to pass around an instance of the object to every little class in the project. However, now I need to manage multiple instances of the previous setup, which means that the singleton pattern breaks since each...

C++ boost thread id and Singleton

hi. Sorry to flood so many questions this week. I assume thread index returned by thread.get_id is implementation specific. In case of the pthreads, is index reused? IE, if thread 0 runs and joins, is thread launched afterwords going to have a different ID? the reason I ask this is a need to implement Singleton pattern with a twist: ...

Singleton Pattern for C#

I need to store a bunch of variables that need to be accessed globally and I'm wondering if a singleton pattern would be applicable. From the examples I've seen, a singleton pattern is just a static class that can't be inherited. But the examples I've seen are overly complex for my needs. What would be the very simplest singleton clas...

Javascript 'class' and singleton problems

I have a singleton object that use another object (not singleton), to require some info to server: var singleton = (function(){ /*_private properties*/ var myRequestManager = new RequestManager(params, //callbacks function(){ previewRender(response); }, function(){ previewError(); } ); /*_pu...

game state singleton cocos2d, initWithEncoder always returns null

Hi, I'm trying to write a basic test "game state" singleton in cocos2d, but for some reason upon loading the app, initWithCoder is never called. Any help would be much appreciated, thanks. Here's my singleton GameState.h: #import "cocos2d.h" @interface GameState : NSObject <NSCoding> { NSInteger level, score; Boolean seenInstruct...

It is related to core java enums.

what is singleton instances of the enumeration class in java? ...

F# How to implement Singleton Pattern (syntax)

I have a cache of data which is getting refreshed from an outside source, and I want to limit my access tot his cache (readonly) inside of my app. I don't want to have refresh the datasource everytime I need access to it (ie. on instantiation go and pull all the data I need, as there is quite a bit of data that is being kept up to date)...

Zend_Registry - Do you need getInstance() ?

Hey I'm wondering when accessing Zend_Registry in an application if you need to include getInstance() and if so, why? for example Zend_Registry::getInstance()->get('db'); vs. Zend_Registry::get('db'); they both seem to work with the later being less verbose. I vaguely understand that Zend_Registry is a singleton, which I t...

PHP OOP: Avoid Singleton/Static Methods in Domain Model Pattern

I understand the importance of Dependency Injection and its role in Unit testing, which is why the following issue is giving me pause: One area where I struggle not to use the Singleton is the Identity Map/Unit of Work pattern (Which keeps tabs on Domain Object state). //Not actual code, but it should demonstrate the point class M...

Replace singletons with what?

Singletons are so often said to be a bad design choice, so how should you design an application when you want to avoid them? ...

Generic Abstract Singleton with Custom Constructor in C#

I want to write a generic singleton with an external constructor. In other words the constructor can be modified. I have 2 designs in my mind but I don't know whether they are practical or not. First one is to enforce derived class' constructor to be non-public but I do not know if there is a way of it? Second one is to use a delegate ...

Calls to singleton library

I have a singleton class, and I will compile it as a library static(lib) or dynamic(dll). Is it guaranteed that calls to same file in a machine always refer to same and unique instance in both cases? Edit: What if a process loads two different library and different functions from these libraries want to use instance of singleton class....

Singleton rule questions (do not allow to create copy and deserialization)

Hi, Reading some article about singleton, I stopped at the point saying: "Do not allow to crate copy of existing instance". I realized that I do not know how would I do that! Could you tell me, please, how could I copy existing instance of class? And the second one: deserializaition. How it could be dangerous? And for both - how to deny...

VB.NET looping through XML to store in singleton

I'm having a problem with looping through an XML file and storing the value in a singleton My XML looks like this <values> <value></value> <value>$1</value> <value>$5,000</value> <value>$10,000</value> <value>$15,000</value> <value>$25,000</value> <value>$50,000</value> ...