title: Why does Microsoft Web API create new static instance for each request?
body: <p>I'm trying to create a singleton object which should be in use for each call to my server.
  But for some reason the static object is keep renew for each call to the Web API.
  Is there any way to stop it? What can I do?</p>
  
  <p>Thanks for the answers, Here is some code:</p>
  
  <p>The Singleton:</p>
  
  <pre><code>private static CoreEngine _instance;
  public static CoreEngine Instance 
      {
          get { return _instance ?? (_instance = new CoreEngine()); }
      }
  private CoreEngine(){}
  </code></pre>
  
  <p>The WebAPI method:</p>
  
  <pre><code>    CoreEngine _coreEngine = CoreEngine.Instance;
  
      [System.Web.Http.Route("Compare")]
      public void PostCompare([FromUri]string pluginName, [FromUri]string file)
      {
          var plugin = _coreEngine.GetPlugin(pluginName);
          if (plugin == null)
              return;
          plugin.Compare(file);
  </code></pre>
  
  <p>And a simple client:</p>
  
  <pre><code> public void Post(string uri, Dictionary&lt;string,string&gt; postDic)
      {
  
  
          using (var client = new HttpClient())
          {
              var postUri = FromDictionaryToUriString(uri, postDic);
  
              var response = client.PostAsync(postUri, null).Result;
          }
      }
  </code></pre>
  
  <p>Its only one thread and sync.
  I tried to repeate the same <code>POST</code> method for two times and in the first time I had the first instance of the <code>CoreEngine</code> while in the secound call, The <code>CoreEngine</code> has been disposed and the instance were re-created.</p>