-
Notifications
You must be signed in to change notification settings - Fork 2
/
FluentValidationExtensions.cs
32 lines (31 loc) · 1.44 KB
/
FluentValidationExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
namespace MassTransit;
/// <summary>
/// Extension methods for injecting functionality from the <see cref="FluentValidation"/> library into a <see cref="MassTransit"/> pipeline.
/// </summary>
public static class FluentValidationExtensions
{
/// <summary>
/// Registers the necessary filters to perform validation on message sent through the pipeline.
/// </summary>
/// <param name="configurator">A MassTransit endpoint configurator.</param>
/// <param name="context">The message handling context, implementing <see cref="IConfigurationServiceProvider"/>.</param>
/// <example>
/// services.AddMassTransit(busConfigurator =>
/// {
/// busConfigurator.AddConsumer<MyHandler>();
/// busConfigurator.UsingRabbitMq((busContext, rabbitMQConfigurator) =>
/// {
/// rabbitMQConfigurator.ReceiveEndpoint(AssemblyName, endpointConfigurator =>
/// {
/// endpointConfigurator.UseFluentValidationForMassTransit(busContext);
/// endpointConfigurator.ConfigureConsumer<MyHandler>(busContext);
/// });
/// });
/// });
/// </example>
public static IEndpointConfigurator UseFluentValidationForMassTransit(this IEndpointConfigurator configurator, IBusRegistrationContext context)
{
configurator.UseConsumeFilter(typeof(FluentValidationFilter<>), context);
return configurator;
}
}