Say I have a WCF service that has access to some data that is shared between multiple clients. What is the difference between these two setups:
1) Instancing: Single, Concurrency: Multiple, with the shared data stored in instance variables.
2) Instancing: Per-Call, Concurrency: Multiple, with the shared data stored in static variables.
Is there any practical difference? Either way, I will have to make sure the shared data is thread-safe, but I’m wondering if there are any advantages for one particular approach.
Notionally, there is no difference. As you’ve said, either way you’re gonna have to synchronize access to the shared data. Practically, the second option is better. From the definitive book on WCF, Programming WCF Services by Juval Lowy:
I use option #2 for my project. The WCF service itself is simply a thin facade to static methods of the classes where the work is performed. For example,
Obviously, I’ve elided many of the details, but this shows the general idea.