gpt4 book ai didi

c# - 为类型为 mediatr.irequesthandler`2 的请求构造处理程序时出错

转载 作者:行者123 更新时间:2023-12-05 06:11:21 28 4
gpt4 key购买 nike

当我将 IMapper 注入(inject) MediatR 命令处理程序时,出现了这个问题。我在此之前正确注入(inject),但之后更改了 AutoMapperMediatR 配置,如下所示。 (我添加了所有应用层的程序集)

services.AddAutoMapper(Assembly.GetExecutingAssembly(),
typeof(CreateAccountCommand).Assembly,
typeof(EfRepository<,>).Assembly,
typeof(IRepository<,>).Assembly,
typeof(KeyValueDto).Assembly);

services.AddMediatR(Assembly.GetExecutingAssembly(),
typeof(CreateAccountCommand).Assembly,
typeof(EfRepository<,>).Assembly,
typeof(IRepository<,>).Assembly,
typeof(KeyValueDto).Assembly);

当我执行 CreateAccountCommand 时,出现如下错误:

Error constructing handler for request of type MediatR.IRequestHandler`2[Application.Actions.Users.Commands.CreateAccountCommand,Application.Common.Models.GenericResponse`1[System.String]]. Register your handlers with the container. See the samples in GitHub for examples.

下面是内部异常

Property 'System.Linq.IQueryable`1[Domain.Entities.Thumbnail] Thumbnails' is not defined for type 'Domain.Entities.Thumbnail' (Parameter 'property')

最佳答案

我也遇到了这个问题,解决方法是在我的应用层添加如下代码,然后在Program中调用

public static IServiceCollection AddApplication(this IServiceCollection services)
{
var assembly = Assembly.GetExecutingAssembly();
return services.AddMediatR(assembly);
}

我的程序代码调用顺序

builder.Services.AddMediatR(Assembly.GetExecutingAssembly())
builder.Services.AddApplication();

关于c# - 为类型为 mediatr.irequesthandler`2 的请求构造处理程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64040375/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com