2017-02-12 20:43:30 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Tapeti.Config;
|
|
|
|
|
|
|
|
|
|
namespace Tapeti.DataAnnotations
|
|
|
|
|
{
|
2019-08-14 10:20:53 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Validates consumed messages using System.ComponentModel.DataAnnotations
|
|
|
|
|
/// </summary>
|
2019-08-15 09:26:55 +00:00
|
|
|
|
internal class DataAnnotationsMessageMiddleware : IMessageMiddleware
|
2017-02-12 20:43:30 +00:00
|
|
|
|
{
|
2019-08-14 10:20:53 +00:00
|
|
|
|
/// <inheritdoc />
|
2017-02-12 20:43:30 +00:00
|
|
|
|
public Task Handle(IMessageContext context, Func<Task> next)
|
|
|
|
|
{
|
|
|
|
|
var validationContext = new ValidationContext(context.Message);
|
2019-07-18 08:02:42 +00:00
|
|
|
|
Validator.ValidateObject(context.Message, validationContext, true);
|
2017-02-12 20:43:30 +00:00
|
|
|
|
|
|
|
|
|
return next();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|