nopCommerce 4.4 migration from 3.8 and getting error related to DependencyRegistrar.cs

140 views Asked by At

I am working on one of the project to migrate from nopCommmerce 3.8 to nopCommerce 4.4. I am facing below issue, please help me to rectify it.

I have a controller called ' TEDPortalController ' where I have added methods from 3.8 related to 'TonerRequest'.

First it fired the below error :

DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Nop.Web.Controllers.TEDPortalController' can be invoked with the available services and parameters: Cannot resolve parameter 'Nop.Services.TonerRequest.ITonerRequestService tonerRequestService' of constructor 'Void .ctor(Nop.Core.IWorkContext, Nop.Services.Logging.ILogger, Nop.Core.Events.IEventPublisher, Nop.Services.TonerRequest.ITonerRequestService)'.

Then I have added 2 lines in DependencyRegistrar.cs as :

services.AddScoped<ITonerRequestService, TonerRequestService>();

services.AddScoped<IEventPublisher, EventPublisher>();

After that I am getting below error :

DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Nop.Services.TonerRequest.TonerRequestService' can be invoked with the available services and parameters: Cannot resolve parameter 'Nop.Core.Data.IRepository`1[Nop.Core.Domain.TonerRequest.TonerRequestMaster] tonerRequestMasterRepository' of constructor 'Void .ctor(Nop.Core.Data.IRepository`1[Nop.Core.Domain.TonerRequest.TonerRequestMaster], Nop.Core.Data.IRepository`1[Nop.Core.Domain.TonerRequest.TonerRequestDetails], Nop.Core.Events.IEventPublisher)'.

I think I need to add more lines into DependencyRegistrar.cs, but I am not able to get what needs to be add there. Request you to please help us to rectify this issue.

1

There are 1 answers

0
Omar On

in Nopcommerce 4.4 you need to Register services into the IServiceCollection, inside NopStartup class in this way:

public class NopStartup : INopStartup
    {
        /// <summary>
        /// Add and configure any of the middleware
        /// </summary>
        /// <param name="services">Collection of service descriptors</param>
        /// <param name="configuration">Configuration of the application</param>
        public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
        {
            services.AddScoped<ITonerRequestService, TonerRequestService>();
         
        }

        /// <summary>
        /// Configure the using of added middleware
        /// </summary>
        /// <param name="application">Builder for configuring an application's request pipeline</param>
        public void Configure(IApplicationBuilder application)
        {
        }

        /// <summary>
        /// Gets order of this startup configuration implementation
        /// </summary>
        public int Order => 3000;
    }

And You don't need to register IEventPublisher, you just need to call the name space Nop.Core.Events