I have a simple interface for caching stuff which goes like this
public interface ICacheService
{
T Get<T>(string cacheId, Func<T> getItemCallback) where T : class;
}
and this works for simple callback functions but in my case I need to add something a bit more complex. I think it’s an anonymous type…
In the controller I am injecting a service that runs a query and this goes like this:
this.queryContainer.Get<ObjectQuery>().Execute(new ObjectParameters(id));
But of course this isn’t of type Func so if I try to use my caching service, the compiler complains.
What sort of interface do I need so that I can get my caching to work?
Ideally I want to do this:
this.cachingService.Get<ObjectResult>(id, this.queryContainer.Get<ObjectQuery>().Execute(new ObjectParameters(id)));
Is it even possible?
Any help is greatly appreciated!
Many thanks
You just need it expressed as a
Func<T>?Try this: