小编mus*_*mus的帖子

MediatR 错误:向容器注册您的处理程序

我有一个 .Net Core 应用程序,我使用 .AddMediatR 扩展来注册命令和处理程序的程序集

在Startup.cs的ConfigureServices中,我使用了官方包MediatR.Extensions.Microsoft.DependencyInjection中的扩展方法,并带有以下参数:

启动.cs

 services.AddBLL();
Run Code Online (Sandbox Code Playgroud)

依赖注入.cs

public static IServiceCollection AddBLL(this IServiceCollection services)
    {
        services.AddAutoMapper(Assembly.GetExecutingAssembly());
        services.AddMediatR(Assembly.GetExecutingAssembly());
        services.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestPerformanceBehaviour<,>));
        services.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestValidationBehavior<,>));

        return services;
    }
Run Code Online (Sandbox Code Playgroud)

命令处理程序类如下:ListEpostaHesaplariHandler.cs

public class ListEpostaHesaplariRequest : IRequest<ResultDataDto<List<ListEpostaHesaplariDto>>>
{
    public FiltreEpostaHesaplariDto Model { get; set; }
}

public class ListEpostaHesaplariHandler : IRequestHandler<ListEpostaHesaplariRequest, ResultDataDto<List<ListEpostaHesaplariDto>>>
{
    private readonly IBaseDbContext _context;
    private readonly IMapper _mapper;

    public ListEpostaHesaplariHandler(IBaseDbContext context, IMapper mapper)
    {
        _context = context;
        _mapper = mapper;
    }

    public async Task<ResultDataDto<List<ListEpostaHesaplariDto>>> Handle(ListEpostaHesaplariRequest request, CancellationToken cancellationToken)
    {
        await Task.Delay(1);

        var …
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection mediatr asp.net-core

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

asp.net-core ×1

c# ×1

dependency-injection ×1

mediatr ×1