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