Search code examples
c#asp.netdesign-patternssingletonmef

What is the Behavior of a Singleton in ASP.NET Web Services?


I want to create a logging component to log errors in my Web services layer to a database through a proprietary API. The Web services layer can be distributed across multiple application servers. I believe the logging component should be a Singleton.

My Web services layer is written in ASP.NET. My logging component is loaded dynamically through System.ComponentModel (a.k.a. MEF).

What is likely to happen when I get the instance of the Singleton? Do I get a separate logging Singleton instance on each application server?


Solution

  • Yes, you will have a different instance on each server. The Singleton pattern guarantees that you will have just one instance in a given Application Domain, and each server has its own.