I've registered an instance of the IMemoryCache (Microsoft.Extensions.Cachine.Memory 3.1.5) as a singleton with a SimpleContainer for use with Caliburn Micro for a WPF application that I'm writing in .Net Core 3.1.
In my Bootstrapper, I have the following code
public class Bootstrapper : BootstrapperBase
{
private SimpleContainer _container = new SimpleContainer();
public Bootstrapper()
{
Initialize();
}
protected override void Configure()
{
_container.Instance(_container);
_container
.Singleton<IWindowManager, WindowManager>()
.Singleton<IEventAggregator, EventAggregator>()
.Singleton<IMemoryCache, MemoryCache>();
}
When I come to use the IMemoryCache in a class it throws an Exception as it requires MemoryCacheOptions to be passed into the constructor of the MemoryCache.
I've tried to add MemoryCacheOptions to the Singleton registration but that's not accepted.
This is the constructor of my ReferenceDataHelper class where I'm trying to inject the IMemoryCache, it fails with a System.Reflection.TargetInvocationException when it constructs the ReferenceDataHelper class.
public class ReferenceDataHelper : IReferenceDataHelper
{
private IMemoryCache _memoryCache;
private IReferenceDataHandler _referenceDataHandler;
public ReferenceDataHelper(IReferenceDataHandler referenceDataHandler, IMemoryCache memoryCache)
{
_referenceDataHandler = referenceDataHandler;
_memoryCache = memoryCache;
}
I can't figure out how to set this up - can anyone offer some help? Thanks!