我正在尝试在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();