[Mono-list] Extending the singleton pattern in C#

PRUTEANU Teodor Alexandru orion@infoiasi.ro
Wed, 11 Sep 2002 13:04:43 +0300 (EEST)


Hello,

Currently, I'm analyzing the singleton pattern in C# and it seems 
that one good way of implementing a singleton is the following:

sealed class Singleton 
{
	public static readonly Instance = new Singleton ();
	private Singleton () {...}
}
class Test {Singleton obj = Singleton.Instance;}

However, this technique does not seem to be so extensible, since there's 
no way to overload the private constructor (well, yes, but useless). 
One solution could be provided using attributes, e.g.

class FooAttribute : Attribute 
{
	// whatever info I need
}
and later on, 
class Test 
{
	[Foo (...)]
	Singleton obj;

	public Test ()
	{
		obj = Singleton.Instance;
	}
}

My question is: how can I access (or transfer) the Foo declared data in my Singleton 
instance constructor? If that's not possible, do you have any other suggestions 
on extending my singleton? There might be other solutions, but I don't catch'em.

Best,

Alexandru Pruteanu
Faculty of Computer Science
Iasi, Romania 
http://students.infoiasi.ro/~orion