1
0
mirror of synced 2024-12-23 01:33:07 +01:00
Tapeti/Tapeti.DataAnnotations/DataAnnotationsPublishMiddleware.cs

23 lines
664 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
{
/// <summary>
/// Validates published messages using System.ComponentModel.DataAnnotations
/// </summary>
internal class DataAnnotationsPublishMiddleware : IPublishMiddleware
2017-02-12 21:43:30 +01:00
{
/// <inheritdoc />
public ValueTask Handle(IPublishContext context, Func<ValueTask> 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
return next();
2017-02-12 21:43:30 +01:00
}
}
}