2

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?

Mathias F
  • 15,906
  • 22
  • 89
  • 159
  • Your registration code looks fine. Are you sure you still get `PerRequestCacheManager`? Have you tried to clean/rebuild your solution? Is `ICategoryService` derives from another interface? Maybe there is some other registration exists for the `ICategoryService` implementations in Nopcommerce ... – nemesv Jul 09 '13 at 15:13
  • 1
    Where (in which project, which class) you have added the custom registration: `builder.RegisterType().As().WithParameter(ResolvedParameter.ForNamed("nop_cache_static")).InstancePerHttpRequest();`? Directly in the nopcommerce source? Have you rebuilt then nopcommerce and used this custom one? Or you have this modification in a custom `DependencyRegistrar`? In this case what does the `Order` proeprty returns? – nemesv Jul 12 '13 at 19:15
  • Have you managed to solve this problem yourself? If yes then you should post the solution, if no can you please check my previous questions and answer them? – nemesv Jul 17 '13 at 04:44

0 Answers0