Hi I am using Ninject IoC container. I can not convert the structuremap code to ninject.
This is Structuremap code binding
For<IProductCatalogService>().Use<ProductCatalogService>().Named("realProductCatalogService");
For<IProductCatalogService>().Use<CachedProductCatalogService>()
.Ctor<IProductCatalogService>().Is(p => p.TheInstanceNamed("realProductCatalogService"));
And I am using Ninject code like this
Kernel.Bind<IProductCatalogService>().To<ProductCatalogService>().Named("realProductCatalogService");
Kernel.Bind<IProductCatalogService>().To<CachedProductCatalogService>().Named("cachedProductCatalogService");
But this not working.
I suggest you want to inject some implementation of
IProductCatalogServiceintoCachedProductCatalogService, that also implementsIProductCatalogServiceand then use this cached implementation in the rest of the application as the default component.With Ninject you can configure it using the
.WhenParentNamedconditional binding like this:When there is a request for
IProductCatalogServiceninject will try to resolve the conditions. If the parent component (that asked for the injection) is named"cached"(theCachedProductCatalogServicein your case) than ninject will returnProductCatalogServiceotherwise it will returnCachedProductCatalogServiceas the default.