1
0
mirror of synced 2024-06-26 06:17:39 +00:00
Tapeti/Tapeti.DataAnnotations/DataAnnotationsPublishMiddleware.cs

24 lines
675 B
C#
Raw Normal View History

2017-02-12 20:43:30 +00: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>
2017-02-12 20:43:30 +00:00
public class DataAnnotationsPublishMiddleware : IPublishMiddleware
{
/// <inheritdoc />
2017-02-12 20:43:30 +00:00
public Task Handle(IPublishContext context, Func<Task> next)
{
var validationContext = new ValidationContext(context.Message);
Validator.ValidateObject(context.Message, validationContext, true);
2017-02-12 20:43:30 +00:00
return next();
}
}
}