Problems with custom service

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
Hello! I have a task and I want to get my custom service

this._orderExtensionService = EngineContext.Current.Resolve<IOrderExtensionService>();


It returns me null. But I register it in dependency register. Could u please explain me why?

    public class DependencyRegistrar : IDependencyRegistrar
    {
        private const string CONTEXT_NAME_ORDER = "nop_object_context_order_extension";

        public void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
        {
          
            builder.RegisterType<OrderExtensionService>().As<IOrderExtensionService>().InstancePerLifetimeScope();
            //data context
            this.RegisterPluginDataContext<OrderExtensionRecordObjectContext>(builder, CONTEXT_NAME_ORDER);
            //override required repository with our custom context
            builder.RegisterType<EfRepository<OrderExtensionRecord>>()
                .As<IRepository<OrderExtensionRecord>>()
                .WithParameter(ResolvedParameter.ForNamed<IDbContext>(CONTEXT_NAME_ORDER))
                .InstancePerLifetimeScope();
        }
        public int Order
        {
            get { return 1; }
        }

6 years ago
art_MOO wrote:
Hello! I have a task and I want to get my custom service

this._orderExtensionService = EngineContext.Current.Resolve<IOrderExtensionService>();


It returns me null. But I register it in dependency register. Could u please explain me why?

    public class DependencyRegistrar : IDependencyRegistrar
    {
        private const string CONTEXT_NAME_ORDER = "nop_object_context_order_extension";

        public void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
        {
          
            builder.RegisterType<OrderExtensionService>().As<IOrderExtensionService>().InstancePerLifetimeScope();
            //data context
            this.RegisterPluginDataContext<OrderExtensionRecordObjectContext>(builder, CONTEXT_NAME_ORDER);
            //override required repository with our custom context
            builder.RegisterType<EfRepository<OrderExtensionRecord>>()
                .As<IRepository<OrderExtensionRecord>>()
                .WithParameter(ResolvedParameter.ForNamed<IDbContext>(CONTEXT_NAME_ORDER))
                .InstancePerLifetimeScope();
        }
        public int Order
        {
            get { return 1; }
        }



If want you can share your plugin with me I will debug the plugin.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.