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 published messages using System.ComponentModel.DataAnnotations
|
|
|
|
|
/// </summary>
|
2019-08-15 11:26:55 +02:00
|
|
|
|
internal class DataAnnotationsPublishMiddleware : IPublishMiddleware
|
2017-02-12 21:43:30 +01:00
|
|
|
|
{
|
2019-08-14 12:20:53 +02:00
|
|
|
|
/// <inheritdoc />
|
2022-02-09 11:26:56 +01:00
|
|
|
|
public ValueTask Handle(IPublishContext context, Func<ValueTask> 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
|
|
|
|
|
2022-02-09 11:26:56 +01:00
|
|
|
|
return next();
|
2017-02-12 21:43:30 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|