I created a small security library in .NET Core that simplifies the rather complex security setup we have at one of my clients. Inside this library I’m using the IMemoryCache to cache some non-volatile data.
When a colleague tried to use this library he told me that he had to add the following line
This doesn’t seem unexpected but the strange this was that in my example project I nowhere added this!? Time to investigate…
A walk through the ASP.NET Core source code (always a fun experience to discover and learn something new about the framework) learned me the following; when you call AddMvc() or AddResponseCaching() the framework will register for you an IMemoryCache behind the scenes.
If you are using a lower level method like AddControllers() this is not the case.
Learned something? Check!