title: Why getting multiple instances of IMemoryCache in ASP.Net Core?
body: <p>I have what I believe is a standard usage of IMemoryCache in my ASP.NET Core application.</p>
  
  <p>In startup.cs I have: </p>
  
  <pre><code>services.AddMemoryCache();
  </code></pre>
  
  <p>In my controllers I have:</p>
  
  <pre><code>private IMemoryCache memoryCache;
  public RoleService(IMemoryCache memoryCache)
  {
      this.memoryCache = memoryCache;
  }
  </code></pre>
  
  <p>Yet when I go through debug, I end up with multiple memory caches with different items in each one. I thought memory cache would be a singleton?</p>
  
  <p><strong>Updated with code sample:</strong></p>
  
  <pre><code>public List&lt;FunctionRole&gt; GetFunctionRoles()
  {
      var cacheKey = "RolesList";
      var functionRoles = this.memoryCache.Get(cacheKey) as List&lt;FunctionRole&gt;;
      if (functionRoles == null)
      {
           functionRoles = this.functionRoleDAL.ListData(orgId);
           this.memoryCache.Set(cacheKey, functionRoles, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromDays(1)));
      }
  }
  </code></pre>
  
  <p>If I run two clients in two different browsers, when I hit the second line I can see this.memoryCache contains different entries.</p>