1
0
mirror of synced 2024-11-25 12:13:10 +01:00
Tapeti/Tapeti.DataAnnotations/DataAnnotationsPublishMiddleware.cs

24 lines
682 B
C#
Raw Normal View History

2017-02-12 21:43:30 +01:00
using System;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using Tapeti.Config;
namespace Tapeti.DataAnnotations
{
/// <inheritdoc />
/// <summary>
/// Validates published messages using System.ComponentModel.DataAnnotations
/// </summary>
internal class DataAnnotationsPublishMiddleware : IPublishMiddleware
2017-02-12 21:43:30 +01:00
{
/// <inheritdoc />
2019-08-15 12:04:03 +02:00
public async Task Handle(IPublishContext context, Func<Task> next)
2017-02-12 21:43:30 +01:00
{
var validationContext = new ValidationContext(context.Message);
Validator.ValidateObject(context.Message, validationContext, true);
2017-02-12 21:43:30 +01:00
2019-08-15 12:04:03 +02:00
await next();
2017-02-12 21:43:30 +01:00
}
}
}