1
0
mirror of synced 2024-11-14 22:33:50 +00:00
Tapeti/Tapeti.DataAnnotations/DataAnnotationsMessageMiddleware.cs

26 lines
737 B
C#
Raw Permalink 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
{
/// <summary>
/// Validates consumed messages using System.ComponentModel.DataAnnotations
/// </summary>
internal class DataAnnotationsMessageMiddleware : IMessageMiddleware
2017-02-12 20:43:30 +00:00
{
/// <inheritdoc />
public ValueTask Handle(IMessageContext context, Func<ValueTask> next)
2017-02-12 20:43:30 +00:00
{
if (context.Message == null)
return next();
2017-02-12 20:43:30 +00:00
var validationContext = new ValidationContext(context.Message);
Validator.ValidateObject(context.Message, validationContext, true);
2017-02-12 20:43:30 +00:00
return next();
2017-02-12 20:43:30 +00:00
}
}
}