title: Problems with singleton pattern inside WCF service method
body: <p>I will go ahead and preface this by saying: I am somewhat new to WCF.</p>
  
  <p>I'm working on a server-side routine that's responsible for doing a great deal of business logic. It's accessible from a client via WCF.</p>
  
  <p>My main WCF method calls off to several other private methods. Instead of passing around all of the "lookup data" I need for the business logic to each private method, I decided to use a singleton instance of a class named DataProvider that contains all of this "lookup data".</p>
  
  <p>At the end of the routine, I "release" the DataProvider's lookup data so the next time the routine is executed, the latest lookup data will be used.</p>
  
  <p>So, here's a simplified example:</p>
  
  <pre><code> public void Generate()
   {
        try
        {
             //populate singleton DataProvider with it's lookup data...
             DataProvider.Instance.LoadLookupData();
  
             //do business logic...
        }
        finally
        {
             //release provider's lookup data...
             DataProvider.Release();
        }
   }
  </code></pre>
  
  <p>This works great until I have two different clients that execute the method at (or near) the same time. Problems occur because they share the same singleton instance and the task who finishes first will release the DataProvider before the other completes.</p>
  
  <p>So...</p>
  
  <p>What are my options here? </p>
  
  <p>I'd like to avoid passing around all of the lookup data so the singleton pattern (or some derivative) seems like a good choice. I also need to be able to support multiple clients calling the method at the same time.</p>
  
  <p>I believe the WCF service is configured as "Per-Call". I'm not sure if there's a way to configure a WCF service so that the static memory is not shared between service invocations.</p>
  
  <p>Any help would be appreciated.</p>