Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am new to designing patterns. I would like to implement Singleton design pattern in my c#.net application.

I have few classes in my application say
Class1, Class2 and Class3

In some pages i call any one of this class, in other i may call all the three classes.

How do i implement singleton pattern in my application.

It would be great if you can provide few samples .

Thanks in advance.
Posted
Comments
Bernhard Hiller 3-Jun-13 9:23am    
Why do you want to use a Singleton pattern? A Singleton is just some kind of "global" object - sometimes that's ok, but there ought to be some reason for doing so.

You can create a manager class to get instances of these classes. You just once create objects and when you need this class you do not create objects and get these instances from manager class. Another solution which I do not choose or appreciate is create a static public instances in a class and just use these without any call.

This is a good example for first solution:

http://msdn.microsoft.com/en-us/library/ff650316.aspx[^]
 
Share this answer
 
If you google or bing for singleton pattern c# you will get over 120k suggestions. Or try using the Search for Articles, questions, tips in the top right hand corner of this codeproject screen to get 47 pages of suggestions from this very site
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900