1
0
mirror of synced 2024-11-16 14:53:50 +00:00
Tapeti/Tapeti.DataAnnotations/DataAnnotationsMessageMiddleware.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
686 B
C#

using System;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using Tapeti.Config;
namespace Tapeti.DataAnnotations
{
/// <inheritdoc />
/// <summary>
/// Validates consumed messages using System.ComponentModel.DataAnnotations
/// </summary>
internal class DataAnnotationsMessageMiddleware : IMessageMiddleware
{
/// <inheritdoc />
public ValueTask Handle(IMessageContext context, Func<ValueTask> next)
{
var validationContext = new ValidationContext(context.Message);
Validator.ValidateObject(context.Message, validationContext, true);
return next();
}
}
}