In Nopcommerce an implementation of an interface ICacheManager is injected into objects that use Caching.
One of such classes is CategoryService
public partial class CategoryService : ICategoryService
{
private readonly ICacheManager _cacheManager;
public CategoryService(ICacheManager cacheManager)
{
}
}
Dependencies are resolved by autofac and using this registration _cacheManager gets an instance of PerRequestCacheManager.
builder.RegisterType<MemoryCacheManager>().As<ICacheManager>().Named<ICacheManager>("nop_cache_static").SingleInstance();
builder.RegisterType<PerRequestCacheManager>().As<ICacheManager>().Named<ICacheManager>("nop_cache_per_request").InstancePerHttpRequest();
builder.RegisterType<CategoryService>().As<ICategoryService>().InstancePerHttpRequest();
I am not shure why PerRequestCacheManager is used. I tried to use this registration to have _cacheManager as an instance of MemoryCacheManager, but I still get an instance of PerRequestCacheManager.
builder.RegisterType<CategoryService>().As<ICategoryService>()
.WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static"))
.InstancePerHttpRequest();
How can I change the registration so that _cacheManager in Category gets an instance of MemoryCacheManager?