what is the difference .WithParameter

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
Dear Experts,

What is the difference between the lines of codes bellow? from DependencyRegistrar.cs
lines 1-3 have .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static"))
then lines 4-5 don't have .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static")).

please explain what is .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static")).


  1) builder.RegisterType<CommonModelFactory>().As<ICommonModelFactory>()
  2) .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static"))
  3) .InstancePerLifetimeScope();


  4) builder.RegisterType<CommonModelFactory>().As<ICommonModelFactory>()
  5) .InstancePerLifetimeScope();
6 years ago
archie748491 wrote:
Dear Experts,

What is the difference between the lines of codes bellow? from DependencyRegistrar.cs
lines 1-3 have .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static"))
then lines 4-5 don't have .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static")).

please explain what is .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static")).


  1) builder.RegisterType<CommonModelFactory>().As<ICommonModelFactory>()
  2) .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static"))
  3) .InstancePerLifetimeScope();


  4) builder.RegisterType<CommonModelFactory>().As<ICommonModelFactory>()
  5) .InstancePerLifetimeScope();


Hi, 1-3 are telling the ioc container exactly which instance to use, by name 'nop_cache_static', rather than letting the ioc container decide because there are different classes that implement ICacheManager (see Nop.Core.Caching).

Look at Nop.Web.Framework.DependencyRegistrar.cs line 139 in v3.90. You see this line...


builder.RegisterType<MemoryCacheManager>().As<ICacheManager>().Named<ICacheManager>("nop_cache_static").SingleInstance();


This is registering the MemoryCacheManager with the name 'nop_cache_static'

4-5 are letting the ioc container create an instance of the default instance.
6 years ago
Thank you very much.

Very well said... I will keep that in mind...
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.