NeleBudde wrote:Hello,
I'm having the same goal, to override a methode from a Service in a Plugin.
I followed your steps, but the original Method is still invoked instead of the override Method.
I just successfully performed this task for a plugin I'm writing for Nop 4.1. Try following these steps:
1) Follow the
instructions on creating a plugin.
2) In your plugin project make sure that you have a DependencyRegistrar class:
public class DependencyRegistrar: IDependencyRegistrar
{
public void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
{
builder.RegisterType<MyService>().As<IMyService>().InstancePerLifetimeScope();
}
public int Order => 1000; // Use a high number here so we get added last and take precedence.
}
3) The important bit is probably the value you assign 'Order'. As Andrei mentions, it should be a 'Big' number to ensure that it is registered after the default implementation.
4) The class called 'MyService' should be the one you create in your plugin and it will be doing the overriding of the original class.
Try this. If it does not work, please post some code.