ASP.Net WebApi2中的Mediatr实现

问题描述 投票:0回答:1

我正在尝试在ASP.Net Web Api中实现mediatr模式。

出现以下错误:

找不到用于类型请求的处理程序MediatR.IRequestHandler`2 [Orion_API.Campaigns.GetCampaigns.GetCampaignsRequest,System.Collections.Generic.List`1 [Orion_API.Campaigns.GetCampaigns.GetCampaignsResponse]]。向容器注册您的处理程序。

我的引导程序类如下:

builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

builder.RegisterGeneric(typeof(GenericRepository<>))
       .As(typeof(IGenericRepository<>))
       .InstancePerRequest();

builder.RegisterType<Mediator>().As<IMediator>().InstancePerLifetimeScope();

builder.Register<ServiceFactory>(context =>
{
    var componentContext = context.Resolve<IComponentContext>();
    return t => {
        object o;

        return componentContext.TryResolve(t, out o) ? o : null;
    };
});


//Set the dependency resolver to be Autofac.  
Container = builder.Build();
asp.net-web-api2 mediatr
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.