Click here to Skip to main content
15,921,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have one class (Concurrency) object in which i am initiating all db related settings .
All this code is in WCF service. For instance management, i have made service instance on persession basis. Now i want to share Concurrency class object through all db layer classes. I was thinking to do this singleton can be used.Though i have used persession instance creation for wcf service, i am confused , how singleton pattern will react for multiple requests at same time. Will each user get same class object or same class object will be shared with all users ?
Posted

The singleton pattern is designed to return the same single instance of your class to all callers.
To handle multiple requests at the same time you can use the lock mechanism.

This MSDN page should give you some good information
http://msdn.microsoft.com/en-us/library/ff650316.aspx[^]

Difficult to give a better answer with the information you have given.
 
Share this answer
 
v2
Comments
V5709 31-Jul-14 5:46am    
Thanks for reply..
1.If you are just want to access and store DB related settings you do not need singleton, you could use static properties that are initialized by static constructor.

2.If you want to implement more complex concurrency scenarios in the context of WCF you could find details in the next article: WCF Concurrency (Single, Multiple, and Reentrant) and Throttling[^]
 
Share this answer
 
Comments
V5709 31-Jul-14 5:46am    
Thanks for reply..
Raul Iloc 31-Jul-14 6:30am    
Welcome!
I had requirement to choose connection string at run time according to client request. so i declared an sealed class which i used to set all my db & other settings. Then i stored that particular object in cache using dictionary object & client id as key value pair.

During execution i checked cache for particular client db setting object, if not found then i created new object & kept my cache updated with new object
 
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