nopCommerce 4.4从3.8迁移并获得与dependencyregistry .cs相关的错误



我正在做一个从nopCommerce 3.8迁移到nopCommerce 4.4的项目。我面临以下问题,请帮我改正

我有一个名为"TEDPortalController"的控制器,其中我添加了与"TonerRequest"相关的3.8方法。

首先触发以下错误:

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)'.

然后我在dependencyregistry .cs中添加了2行:

services.AddScoped<ITonerRequestService, TonerRequestService>();

services.AddScoped<IEventPublisher, EventPublisher>();

之后我得到以下错误:

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)'.

我想我需要添加更多的行到dependencyregistry .cs,但我无法得到什么需要在那里添加。请您帮助我们解决这个问题。

在Nopcommerce 4.4中,你需要注册服务到IServiceCollection中,在NopStartup类中,以这种方式:

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;
}

你不需要注册IEventPublisher,你只需要调用名称空间no . core . events

相关内容

最新更新