【发布时间】:2020-03-20 07:47:21
【问题描述】:
我正在尝试在 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();
【问题讨论】:
-
应用从哪里调用“public static IServiceCollection AddApplication(this IServiceCollection services)”方法。
-
顺便说一句,您可以通过在 github 搜索框(左上角)中搜索 AddApplication 来找到它