I have been looking at controller classes in .NET Core with constructors that take IMemoryCache
arguments but cannot see where the passed objects come from originally. For instance, this example declaration from Cache in-memory in ASP.NET Core:
public class HomeController : Controller
{
private IMemoryCache _cache;
public HomeController(IMemoryCache memoryCache)
{
_cache = memoryCache;
}
}
Where would this constructor be called and how is the IMemoryCache
object instantiated in the first place? Is this something that happens behind the scenes with .NET Core that does not have to be coded explicitly? I have seen similar examples using an ILogger object, so my question would also apply to that.