How to override factory into a plugin ?

3 years ago
Hello (Sorry for my bad English)

I'm writing a plugin.
When i override a service. it's ok but when i ovveride a factory, its not ok.
This is my plugin code.

DependencyRegistrar :


public class DependencyRegistrar : IDependencyRegistrar
    {

        public void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
        {

            builder.RegisterType<ProductServiceCustom>().As<IProductService>().InstancePerLifetimeScope();  
            builder.RegisterType<ProductModelFactoryCustom>().As<IProductModelFactory>()
                .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static"))
                .InstancePerLifetimeScope();
        }

        public int Order
        {
            get { return 1; }
        }
    }



ProductServiceCustom :

public partial class ProductServiceCustom : ProductService


public override IPagedList<Product> SearchProducts


ProductModelFactoryCustom :

public partial class ProductModelFactoryCustom : ProductModelFactory


public override IEnumerable<ProductOverviewModel> PrepareProductOverviewModels



What's the problem ? I have no error


Thx :-)
3 years ago
i'm relatively new to nopCommerce, and had the problem today where my custom ProductModelFactory and ShoppingCartModelFactory where not executed.

It seems in your IDependencyRegistrar, the order should be higher than 1.
3 years ago
[email protected] wrote:
i'm relatively new to nopCommerce, and had the problem today where my custom ProductModelFactory and ShoppingCartModelFactory where not executed.

It seems in your IDependencyRegistrar, the order should be higher than 1.


Thanks for the post.
I just figured out the original ModelFactory that was registered in Nop.Web/Infrastructure/DependencyRegistrar.cs when order as 1.
It must higher than 1 to overrode the ModelFactory. Feel so new and so much to learn.