1
0
mirror of synced 2024-12-11 20:13:08 +01:00
Tapeti/Tapeti.DataAnnotations/DataAnnotationsPublishMiddleware.cs
Mark van Renswoude 165680fd38 Added ValueTask support
- This is a breaking change for custom middleware implementations
Added validation for return type handling
- This may be breaking for incorrect implementations, but highly unlikely
2022-02-09 11:27:07 +01:00

24 lines
687 B
C#

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
{
/// <inheritdoc />
public ValueTask Handle(IPublishContext context, Func<ValueTask> next)
{
var validationContext = new ValidationContext(context.Message);
Validator.ValidateObject(context.Message, validationContext, true);
return next();
}
}
}