sarahlisa
sarahlisa

Reputation: 131

IMemoryCache gets injected without adding it

I have switched my application from MemoryCache to DistributedSqlServerCache. After commenting out services.AddMemoryCache(), I noticed that IMemoryCache gets still injected in my classes. I use aspnet-core 2.1.

The code that adds the cache to the services:

//services.AddMemoryCache();
services.AddDistributedSqlServerCache(o =>
{
    o.ConnectionString = ConnectionString;
    o.SchemaName = "dbo";
    o.TableName = "tbSessionCache";
});

Proof that it still gets inejcted:

enter image description here

Why does this happen? I think I may not get how this works. Thanks a lot!

Upvotes: 0

Views: 1768

Answers (1)

Henk Mollema
Henk Mollema

Reputation: 46661

MVC adds a default memory cache implementation when configuring the Razor view engine. It is consumed by the cache tag helper: https://github.com/aspnet/Mvc/blob/17d2545b557863955cb5838fa16c6318931ac659/src/Microsoft.AspNetCore.Mvc.Razor/DependencyInjection/MvcRazorMvcCoreBuilderExtensions.cs#L224.

Upvotes: 1

Related Questions