【发布时间】:2020-10-20 11:43:52
【问题描述】:
我正在学习 CQRS 并在 DDD 项目中实施 MediatR。 我有以下项目结构:
Domain
- Commands
- Requests
- Handlers
- Models
- Interfaces
- Repositories
CrossCutting
NativeInjectionBootstrapper.cs
Presentation
- Controllers
因此,在 Presentation Project 中,我使用 NativeInjectionBootstrapper.cs 注入了所有存储库和其他依赖项,并在 Startup.cs 中添加了 services.AddMediatR(typeof(Startup))。
在Domain > Commands > Request 中,我实现了IRequest<> 接口。
在Domain > Commands > Handlers 中,我实现了IRequestHandler<> 接口。
接口注入成功,但是当请求控制器时我收到以下错误:
System.InvalidOperationException:
Handler was not found for request of type MediatR.IRequestHandler`2 [Domain.Commands.Requests.Product.NewProductRequest,System.String].
Register your handlers with the container.
See the samples in GitHub for examples.
我在这里寻求帮助,有人建议在启动时添加另一种类型的 MediatR,例如 services.AddMediatR(typeof(AddEducationCommand).GetTypeInfo().Assembly);,但我没有成功。
我正在搜索如何注册处理程序,但我找不到任何东西。
【问题讨论】:
-
当我只使用一个项目时,一切正常,但是当我分成项目时,我得到了错误。
标签: asp.net-core-webapi mediatr