mediatr

Registering generic type with type constraint in .NET Core (MS.DI)

时光怂恿深爱的人放手 提交于 2021-02-10 14:06:17
问题 I have a generic interface IPipelineBehavior<TRequest, TResponse> (from MediatR). I'm trying to register a specific behavior for this interface as follows: services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationMiddleware<,>)); ValidationMiddleware implements IPipelineBehavior like so: public class ValidationMiddleware<TRequest, TResponse> : IPipelineBehavior<TRequest, Result<TResponse>> Result is a custom class I want all of my MediatR IRequestHandlers to return. When the app

Mocking MediatR 3 with Moq

陌路散爱 提交于 2021-02-06 15:24:18
问题 We've recently started using MediatR to allow us to de-clutter controller actions as we re-factor a large customer facing portal and convert it all to C#. As part of this we are increasing our unit test coverage as well, but I've hit a problem when trying to mock MediatR itself. The command does a bunch of stuff to initiate a process and part of this is sending a notification. The notification itself is dealt with by its own handler and therefore would be subject to its own unit test so I

Mocking MediatR 3 with Moq

心已入冬 提交于 2021-02-06 15:19:00
问题 We've recently started using MediatR to allow us to de-clutter controller actions as we re-factor a large customer facing portal and convert it all to C#. As part of this we are increasing our unit test coverage as well, but I've hit a problem when trying to mock MediatR itself. The command does a bunch of stuff to initiate a process and part of this is sending a notification. The notification itself is dealt with by its own handler and therefore would be subject to its own unit test so I

Using ModelState Outside of a Controller

妖精的绣舞 提交于 2021-01-29 08:20:37
问题 I'm working on moving my API logic in my PATCH endpoint to a Mediatr Command. When applying my patch document, I usually check the model state like below. Normally, I'm doing this from a controller so there is no issue, but when moving this into a RequestHandler, I no longer have access to the model state property since I'm outside of the controller. How would you recommend going about this? Here is the model state logic I'd like to use outside of the controller:

ASP.NET Core MediatR error: Register your handlers with the container

别说谁变了你拦得住时间么 提交于 2020-12-29 02:47:07
问题 I have a .Net Core app where i use the .AddMediatR extension to register the assembly for my commands and handlers following a CQRS approach. In ConfigureServices in Startup.cs i have used the extension method from the official package MediatR.Extensions.Microsoft.DependencyInjection with the following parameter: services.AddMediatR(typeof(AddEducationCommand).GetTypeInfo().Assembly); The command and commandhandler classes are as follow: AddEducationCommand.cs public class AddEducationCommand

ASP.NET Core MediatR error: Register your handlers with the container

拈花ヽ惹草 提交于 2020-12-29 02:46:37
问题 I have a .Net Core app where i use the .AddMediatR extension to register the assembly for my commands and handlers following a CQRS approach. In ConfigureServices in Startup.cs i have used the extension method from the official package MediatR.Extensions.Microsoft.DependencyInjection with the following parameter: services.AddMediatR(typeof(AddEducationCommand).GetTypeInfo().Assembly); The command and commandhandler classes are as follow: AddEducationCommand.cs public class AddEducationCommand

Get specific interface for a single specified concrete type, with decorators applied with Simple Injector

烈酒焚心 提交于 2020-05-28 05:48:09
问题 I am using SimpleInjector with MediatR and hooking up my INotifications and INotificationHandlers<INotification> with attributes on my implementation classes - this is so we can map message bus messages (aka notifications) to notification handlers: Host app receives message from bus Message is parsed into Notification POCO Container is used to look up notification handler(s) Notification is dispatched to each handler Traditionally one would register all INotificationHandler<> with Container

Get specific interface for a single specified concrete type, with decorators applied with Simple Injector

為{幸葍}努か 提交于 2020-05-28 05:46:29
问题 I am using SimpleInjector with MediatR and hooking up my INotifications and INotificationHandlers<INotification> with attributes on my implementation classes - this is so we can map message bus messages (aka notifications) to notification handlers: Host app receives message from bus Message is parsed into Notification POCO Container is used to look up notification handler(s) Notification is dispatched to each handler Traditionally one would register all INotificationHandler<> with Container

Get specific interface for a single specified concrete type, with decorators applied with Simple Injector

有些话、适合烂在心里 提交于 2020-05-28 05:46:06
问题 I am using SimpleInjector with MediatR and hooking up my INotifications and INotificationHandlers<INotification> with attributes on my implementation classes - this is so we can map message bus messages (aka notifications) to notification handlers: Host app receives message from bus Message is parsed into Notification POCO Container is used to look up notification handler(s) Notification is dispatched to each handler Traditionally one would register all INotificationHandler<> with Container

Get specific interface for a single specified concrete type, with decorators applied with Simple Injector

谁都会走 提交于 2020-05-28 05:46:06
问题 I am using SimpleInjector with MediatR and hooking up my INotifications and INotificationHandlers<INotification> with attributes on my implementation classes - this is so we can map message bus messages (aka notifications) to notification handlers: Host app receives message from bus Message is parsed into Notification POCO Container is used to look up notification handler(s) Notification is dispatched to each handler Traditionally one would register all INotificationHandler<> with Container