1
0
mirror of synced 2024-11-05 02:59:16 +00:00
Tapeti/Default/MessageBinding.cs

24 lines
760 B
C#

using System;
using Tapeti.Config;
namespace Tapeti.Default
{
public class MessageBinding : IBindingMiddleware
{
public void Handle(IBindingContext context, Action next)
{
if (context.Parameters.Count == 0)
throw new TopologyConfigurationException("First parameter must be a message class");
var parameter = context.Parameters[0];
if (!parameter.Info.ParameterType.IsClass)
throw new TopologyConfigurationException($"First parameter {parameter.Info.Name} must be a message class");
parameter.SetBinding(messageContext => messageContext.Message);
context.MessageClass = parameter.Info.ParameterType;
next();
}
}
}