I am trying to implement IMemoryClass like I have in other .NET projects with controllers, but now with Minimal API.
However, there is no class like there was in the controller for me to use DI to implement the cache like so:
public class APIController: ControllerBase
{
private readonly IMemoryCache? _cache;
public APIController(IMemoryCache memoryCache)
{
_cache = memoryCache;
}
}
I don't have a class (at least that I'm aware of) to use to pass the instance to, and I can't even create the private readonly IMemoryCache
because it returns error:
A namespace cannot directly contain members such as fields, methods or statements
No search I've done returns anything that I can find relating to minimal APIs and how to start to work on fixing this.
Would anyone help me to point me in the right direction?