2016-12-11 14:08:58 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Tapeti.Annotations;
|
|
|
|
|
using Tapeti.Config;
|
|
|
|
|
using Tapeti.Default;
|
|
|
|
|
using Tapeti.Helpers;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Tapeti
|
|
|
|
|
{
|
|
|
|
|
public class TopologyConfigurationException : Exception
|
|
|
|
|
{
|
|
|
|
|
public TopologyConfigurationException(string message) : base(message) { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public delegate Task<object> MessageHandlerFunc(IMessageContext context, object message);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class TapetiConfig
|
|
|
|
|
{
|
|
|
|
|
private readonly Dictionary<string, List<Binding>> staticRegistrations = new Dictionary<string, List<Binding>>();
|
|
|
|
|
private readonly Dictionary<Type, List<Binding>> dynamicRegistrations = new Dictionary<Type, List<Binding>>();
|
|
|
|
|
|
|
|
|
|
private readonly List<IBindingMiddleware> bindingMiddleware = new List<IBindingMiddleware>();
|
|
|
|
|
private readonly List<IMessageMiddleware> messageMiddleware = new List<IMessageMiddleware>();
|
|
|
|
|
|
|
|
|
|
private readonly string exchange;
|
|
|
|
|
private readonly IDependencyResolver dependencyResolver;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TapetiConfig(string exchange, IDependencyResolver dependencyResolver)
|
|
|
|
|
{
|
|
|
|
|
this.exchange = exchange;
|
|
|
|
|
this.dependencyResolver = dependencyResolver;
|
|
|
|
|
|
2017-01-31 11:01:08 +00:00
|
|
|
|
Use(new DependencyResolverBinding());
|
2016-12-11 14:08:58 +00:00
|
|
|
|
Use(new MessageBinding());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IConfig Build()
|
|
|
|
|
{
|
2017-01-31 11:01:08 +00:00
|
|
|
|
RegisterDefaults();
|
2016-12-11 14:08:58 +00:00
|
|
|
|
|
|
|
|
|
var queues = new List<IQueue>();
|
|
|
|
|
queues.AddRange(staticRegistrations.Select(qb => new Queue(new QueueInfo { Dynamic = false, Name = qb.Key }, qb.Value)));
|
|
|
|
|
|
|
|
|
|
// Group all bindings with the same index into queues, this will
|
|
|
|
|
// ensure each message type is unique on their queue
|
|
|
|
|
var dynamicBindings = new List<List<Binding>>();
|
|
|
|
|
foreach (var bindings in dynamicRegistrations.Values)
|
|
|
|
|
{
|
|
|
|
|
while (dynamicBindings.Count < bindings.Count)
|
|
|
|
|
dynamicBindings.Add(new List<Binding>());
|
|
|
|
|
|
|
|
|
|
for (var bindingIndex = 0; bindingIndex < bindings.Count; bindingIndex++)
|
|
|
|
|
dynamicBindings[bindingIndex].Add(bindings[bindingIndex]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
queues.AddRange(dynamicBindings.Select(bl => new Queue(new QueueInfo { Dynamic = true }, bl)));
|
|
|
|
|
|
2017-01-31 11:01:08 +00:00
|
|
|
|
var config = new Config(exchange, dependencyResolver, messageMiddleware, queues);
|
|
|
|
|
(dependencyResolver as IDependencyContainer)?.RegisterConfig(config);
|
|
|
|
|
|
|
|
|
|
return config;
|
2016-12-11 14:08:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TapetiConfig Use(IBindingMiddleware handler)
|
|
|
|
|
{
|
|
|
|
|
bindingMiddleware.Add(handler);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TapetiConfig Use(IMessageMiddleware handler)
|
|
|
|
|
{
|
|
|
|
|
messageMiddleware.Add(handler);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TapetiConfig Use(IMiddlewareBundle bundle)
|
|
|
|
|
{
|
|
|
|
|
foreach (var middleware in bundle.GetContents(dependencyResolver))
|
|
|
|
|
{
|
|
|
|
|
// ReSharper disable once CanBeReplacedWithTryCastAndCheckForNull
|
|
|
|
|
if (middleware is IBindingMiddleware)
|
|
|
|
|
Use((IBindingMiddleware) middleware);
|
|
|
|
|
else if (middleware is IMessageMiddleware)
|
|
|
|
|
Use((IMessageMiddleware)middleware);
|
|
|
|
|
else
|
|
|
|
|
throw new ArgumentException($"Unsupported middleware implementation: {middleware.GetType().Name}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-01-31 11:01:08 +00:00
|
|
|
|
public void RegisterDefaults()
|
|
|
|
|
{
|
|
|
|
|
var container = dependencyResolver as IDependencyContainer;
|
|
|
|
|
if (container != null)
|
|
|
|
|
{
|
|
|
|
|
if (ConsoleHelper.IsAvailable())
|
|
|
|
|
container.RegisterDefault<ILogger, ConsoleLogger>();
|
|
|
|
|
else
|
|
|
|
|
container.RegisterDefault<ILogger, DevNullLogger>();
|
|
|
|
|
|
|
|
|
|
container.RegisterDefault<IMessageSerializer, JsonMessageSerializer>();
|
|
|
|
|
container.RegisterDefault<IExchangeStrategy, NamespaceMatchExchangeStrategy>();
|
|
|
|
|
container.RegisterDefault<IRoutingKeyStrategy, TypeNameRoutingKeyStrategy>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-12-11 14:08:58 +00:00
|
|
|
|
public TapetiConfig RegisterController(Type controller)
|
|
|
|
|
{
|
|
|
|
|
var controllerQueueInfo = GetQueueInfo(controller);
|
|
|
|
|
|
|
|
|
|
foreach (var method in controller.GetMembers(BindingFlags.Public | BindingFlags.Instance)
|
|
|
|
|
.Where(m => m.MemberType == MemberTypes.Method && m.DeclaringType != typeof(object))
|
|
|
|
|
.Select(m => (MethodInfo)m))
|
|
|
|
|
{
|
|
|
|
|
var methodQueueInfo = GetQueueInfo(method) ?? controllerQueueInfo;
|
|
|
|
|
if (!methodQueueInfo.IsValid)
|
|
|
|
|
throw new TopologyConfigurationException($"Method {method.Name} or controller {controller.Name} requires a queue attribute");
|
|
|
|
|
|
2017-01-31 11:01:08 +00:00
|
|
|
|
var context = new BindingContext(method);
|
2016-12-11 14:08:58 +00:00
|
|
|
|
var messageHandler = GetMessageHandler(context, method);
|
|
|
|
|
|
|
|
|
|
var handlerInfo = new Binding
|
|
|
|
|
{
|
|
|
|
|
Controller = controller,
|
|
|
|
|
Method = method,
|
|
|
|
|
QueueInfo = methodQueueInfo,
|
|
|
|
|
MessageClass = context.MessageClass,
|
2017-01-31 11:01:08 +00:00
|
|
|
|
MessageHandler = messageHandler,
|
|
|
|
|
MessageMiddleware = context.MessageMiddleware
|
2016-12-11 14:08:58 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (methodQueueInfo.Dynamic.GetValueOrDefault())
|
|
|
|
|
AddDynamicRegistration(context, handlerInfo);
|
|
|
|
|
else
|
|
|
|
|
AddStaticRegistration(context, handlerInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TapetiConfig RegisterAllControllers(Assembly assembly)
|
|
|
|
|
{
|
|
|
|
|
foreach (var type in assembly.GetTypes().Where(t => t.IsDefined(typeof(MessageControllerAttribute))))
|
|
|
|
|
RegisterController(type);
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TapetiConfig RegisterAllControllers()
|
|
|
|
|
{
|
|
|
|
|
return RegisterAllControllers(Assembly.GetCallingAssembly());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected MessageHandlerFunc GetMessageHandler(IBindingContext context, MethodInfo method)
|
|
|
|
|
{
|
2017-01-31 11:01:08 +00:00
|
|
|
|
MiddlewareHelper.Go(bindingMiddleware, (handler, next) => handler.Handle(context, next), () => {});
|
2016-12-11 14:08:58 +00:00
|
|
|
|
|
|
|
|
|
if (context.MessageClass == null)
|
|
|
|
|
throw new TopologyConfigurationException($"Method {method.Name} in controller {method.DeclaringType?.Name} does not resolve to a message class");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var invalidBindings = context.Parameters.Where(p => !p.HasBinding).ToList();
|
|
|
|
|
|
|
|
|
|
// ReSharper disable once InvertIf - doesn't make the flow clearer imo
|
|
|
|
|
if (invalidBindings.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var parameterNames = string.Join(", ", invalidBindings.Select(p => p.Info.Name));
|
|
|
|
|
throw new TopologyConfigurationException($"Method {method.Name} in controller {method.DeclaringType?.Name} has unknown parameters: {parameterNames}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return WrapMethod(method, context.Parameters.Select(p => ((IBindingParameterAccess)p).GetBinding()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected MessageHandlerFunc WrapMethod(MethodInfo method, IEnumerable<ValueFactory> parameters)
|
|
|
|
|
{
|
|
|
|
|
if (method.ReturnType == typeof(void))
|
|
|
|
|
return WrapNullMethod(method, parameters);
|
|
|
|
|
|
|
|
|
|
if (method.ReturnType == typeof(Task))
|
|
|
|
|
return WrapTaskMethod(method, parameters);
|
|
|
|
|
|
|
|
|
|
if (method.ReturnType == typeof(Task<>))
|
|
|
|
|
{
|
|
|
|
|
var genericArguments = method.GetGenericArguments();
|
|
|
|
|
if (genericArguments.Length != 1)
|
|
|
|
|
throw new ArgumentException($"Method {method.Name} in controller {method.DeclaringType?.Name} must have exactly one generic argument to Task<>");
|
|
|
|
|
|
|
|
|
|
if (!genericArguments[0].IsClass)
|
|
|
|
|
throw new ArgumentException($"Method {method.Name} in controller {method.DeclaringType?.Name} must have an object generic argument to Task<>");
|
|
|
|
|
|
|
|
|
|
return WrapGenericTaskMethod(method, parameters);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (method.ReturnType.IsClass)
|
|
|
|
|
return WrapObjectMethod(method, parameters);
|
|
|
|
|
|
|
|
|
|
throw new ArgumentException($"Method {method.Name} in controller {method.DeclaringType?.Name} has an invalid return type");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected MessageHandlerFunc WrapNullMethod(MethodInfo method, IEnumerable<ValueFactory> parameters)
|
|
|
|
|
{
|
|
|
|
|
return (context, message) =>
|
|
|
|
|
{
|
|
|
|
|
method.Invoke(context.Controller, parameters.Select(p => p(context)).ToArray());
|
|
|
|
|
return Task.FromResult<object>(null);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected MessageHandlerFunc WrapTaskMethod(MethodInfo method, IEnumerable<ValueFactory> parameters)
|
|
|
|
|
{
|
|
|
|
|
return async (context, message) =>
|
|
|
|
|
{
|
|
|
|
|
await (Task)method.Invoke(context.Controller, parameters.Select(p => p(context)).ToArray());
|
|
|
|
|
return Task.FromResult<object>(null);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected MessageHandlerFunc WrapGenericTaskMethod(MethodInfo method, IEnumerable<ValueFactory> parameters)
|
|
|
|
|
{
|
|
|
|
|
return (context, message) =>
|
|
|
|
|
{
|
|
|
|
|
return (Task<object>)method.Invoke(context.Controller, parameters.Select(p => p(context)).ToArray());
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected MessageHandlerFunc WrapObjectMethod(MethodInfo method, IEnumerable<ValueFactory> parameters)
|
|
|
|
|
{
|
|
|
|
|
return (context, message) =>
|
|
|
|
|
{
|
|
|
|
|
return Task.FromResult(method.Invoke(context.Controller, parameters.Select(p => p(context)).ToArray()));
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void AddStaticRegistration(IBindingContext context, Binding binding)
|
|
|
|
|
{
|
|
|
|
|
if (staticRegistrations.ContainsKey(binding.QueueInfo.Name))
|
|
|
|
|
{
|
|
|
|
|
var existing = staticRegistrations[binding.QueueInfo.Name];
|
|
|
|
|
|
|
|
|
|
// Technically we could easily do multicasting, but it complicates exception handling and requeueing
|
2017-01-31 11:01:08 +00:00
|
|
|
|
// TODO allow multiple, if there is a filter which guarantees uniqueness
|
|
|
|
|
// TODO move to independant validation middleware
|
2016-12-11 14:08:58 +00:00
|
|
|
|
if (existing.Any(h => h.MessageClass == binding.MessageClass))
|
|
|
|
|
throw new TopologyConfigurationException($"Multiple handlers for message class {binding.MessageClass.Name} in queue {binding.QueueInfo.Name}");
|
|
|
|
|
|
|
|
|
|
existing.Add(binding);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
staticRegistrations.Add(binding.QueueInfo.Name, new List<Binding> { binding });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void AddDynamicRegistration(IBindingContext context, Binding binding)
|
|
|
|
|
{
|
|
|
|
|
if (dynamicRegistrations.ContainsKey(context.MessageClass))
|
|
|
|
|
dynamicRegistrations[context.MessageClass].Add(binding);
|
|
|
|
|
else
|
|
|
|
|
dynamicRegistrations.Add(context.MessageClass, new List<Binding> { binding });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected QueueInfo GetQueueInfo(MemberInfo member)
|
|
|
|
|
{
|
|
|
|
|
var dynamicQueueAttribute = member.GetCustomAttribute<DynamicQueueAttribute>();
|
|
|
|
|
var staticQueueAttribute = member.GetCustomAttribute<StaticQueueAttribute>();
|
|
|
|
|
|
|
|
|
|
if (dynamicQueueAttribute != null && staticQueueAttribute != null)
|
|
|
|
|
throw new TopologyConfigurationException($"Cannot combine static and dynamic queue attributes on {member.Name}");
|
|
|
|
|
|
|
|
|
|
if (dynamicQueueAttribute != null)
|
|
|
|
|
return new QueueInfo { Dynamic = true };
|
|
|
|
|
|
|
|
|
|
if (staticQueueAttribute != null)
|
|
|
|
|
return new QueueInfo { Dynamic = false, Name = staticQueueAttribute.Name };
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected class QueueInfo
|
|
|
|
|
{
|
|
|
|
|
public bool? Dynamic { get; set; }
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool IsValid => Dynamic.HasValue || !string.IsNullOrEmpty(Name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected class Config : IConfig
|
|
|
|
|
{
|
|
|
|
|
public string Exchange { get; }
|
|
|
|
|
public IDependencyResolver DependencyResolver { get; }
|
|
|
|
|
public IReadOnlyList<IMessageMiddleware> MessageMiddleware { get; }
|
|
|
|
|
public IEnumerable<IQueue> Queues { get; }
|
|
|
|
|
|
2017-01-31 11:01:08 +00:00
|
|
|
|
private readonly Dictionary<MethodInfo, IBinding> bindingMethodLookup;
|
|
|
|
|
|
2016-12-11 14:08:58 +00:00
|
|
|
|
|
|
|
|
|
public Config(string exchange, IDependencyResolver dependencyResolver, IReadOnlyList<IMessageMiddleware> messageMiddleware, IEnumerable<IQueue> queues)
|
|
|
|
|
{
|
|
|
|
|
Exchange = exchange;
|
|
|
|
|
DependencyResolver = dependencyResolver;
|
|
|
|
|
MessageMiddleware = messageMiddleware;
|
2017-01-31 11:01:08 +00:00
|
|
|
|
Queues = queues.ToList();
|
|
|
|
|
|
|
|
|
|
bindingMethodLookup = Queues.SelectMany(q => q.Bindings).ToDictionary(b => b.Method, b => b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IBinding GetBinding(Delegate method)
|
|
|
|
|
{
|
|
|
|
|
IBinding binding;
|
|
|
|
|
return bindingMethodLookup.TryGetValue(method.Method, out binding) ? binding : null;
|
2016-12-11 14:08:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected class Queue : IQueue
|
|
|
|
|
{
|
|
|
|
|
public bool Dynamic { get; }
|
|
|
|
|
public string Name { get; }
|
|
|
|
|
public IEnumerable<IBinding> Bindings { get; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Queue(QueueInfo queue, IEnumerable<IBinding> bindings)
|
|
|
|
|
{
|
|
|
|
|
Dynamic = queue.Dynamic.GetValueOrDefault();
|
|
|
|
|
Name = queue.Name;
|
|
|
|
|
Bindings = bindings;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-01-31 11:01:08 +00:00
|
|
|
|
protected class Binding : IDynamicQueueBinding
|
2016-12-11 14:08:58 +00:00
|
|
|
|
{
|
|
|
|
|
public Type Controller { get; set; }
|
|
|
|
|
public MethodInfo Method { get; set; }
|
|
|
|
|
public Type MessageClass { get; set; }
|
2017-01-31 11:01:08 +00:00
|
|
|
|
public string QueueName { get; set; }
|
|
|
|
|
|
|
|
|
|
public IReadOnlyList<IMessageMiddleware> MessageMiddleware { get; set; }
|
|
|
|
|
|
|
|
|
|
private QueueInfo queueInfo;
|
|
|
|
|
public QueueInfo QueueInfo
|
|
|
|
|
{
|
|
|
|
|
get { return queueInfo; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
QueueName = (value?.Dynamic).GetValueOrDefault() ? value?.Name : null;
|
|
|
|
|
queueInfo = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-11 14:08:58 +00:00
|
|
|
|
|
|
|
|
|
public MessageHandlerFunc MessageHandler { get; set; }
|
|
|
|
|
|
|
|
|
|
|
2017-01-31 11:01:08 +00:00
|
|
|
|
public void SetQueueName(string queueName)
|
|
|
|
|
{
|
|
|
|
|
QueueName = queueName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-12-11 14:08:58 +00:00
|
|
|
|
public bool Accept(object message)
|
|
|
|
|
{
|
|
|
|
|
return message.GetType() == MessageClass;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Task<object> Invoke(IMessageContext context, object message)
|
|
|
|
|
{
|
|
|
|
|
return MessageHandler(context, message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal interface IBindingParameterAccess
|
|
|
|
|
{
|
|
|
|
|
ValueFactory GetBinding();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-01-31 11:01:08 +00:00
|
|
|
|
|
|
|
|
|
internal interface IBindingResultAccess
|
|
|
|
|
{
|
|
|
|
|
ResultHandler GetHandler();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-12-11 14:08:58 +00:00
|
|
|
|
internal class BindingContext : IBindingContext
|
|
|
|
|
{
|
2017-01-31 11:01:08 +00:00
|
|
|
|
private List<IMessageMiddleware> messageMiddleware;
|
|
|
|
|
private List<IBindingFilter> bindingFilters;
|
|
|
|
|
|
2016-12-11 14:08:58 +00:00
|
|
|
|
public Type MessageClass { get; set; }
|
2017-01-31 11:01:08 +00:00
|
|
|
|
|
|
|
|
|
public MethodInfo Method { get; }
|
2016-12-11 14:08:58 +00:00
|
|
|
|
public IReadOnlyList<IBindingParameter> Parameters { get; }
|
2017-01-31 11:01:08 +00:00
|
|
|
|
public IBindingResult Result { get; }
|
2016-12-11 14:08:58 +00:00
|
|
|
|
|
2017-01-31 11:01:08 +00:00
|
|
|
|
public IReadOnlyList<IMessageMiddleware> MessageMiddleware => messageMiddleware;
|
|
|
|
|
public IReadOnlyList<IBindingFilter> BindingFilters => bindingFilters;
|
2016-12-11 14:08:58 +00:00
|
|
|
|
|
2017-01-31 11:01:08 +00:00
|
|
|
|
|
|
|
|
|
public BindingContext(MethodInfo method)
|
2016-12-11 14:08:58 +00:00
|
|
|
|
{
|
2017-01-31 11:01:08 +00:00
|
|
|
|
Method = method;
|
|
|
|
|
|
|
|
|
|
Parameters = method.GetParameters().Select(p => new BindingParameter(p)).ToList();
|
|
|
|
|
Result = new BindingResult(method.ReturnParameter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Use(IMessageMiddleware middleware)
|
|
|
|
|
{
|
|
|
|
|
if (messageMiddleware == null)
|
|
|
|
|
messageMiddleware = new List<IMessageMiddleware>();
|
|
|
|
|
|
|
|
|
|
messageMiddleware.Add(middleware);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Use(IBindingFilter filter)
|
|
|
|
|
{
|
|
|
|
|
if (bindingFilters == null)
|
|
|
|
|
bindingFilters = new List<IBindingFilter>();
|
|
|
|
|
|
|
|
|
|
bindingFilters.Add(filter);
|
2016-12-11 14:08:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal class BindingParameter : IBindingParameter, IBindingParameterAccess
|
|
|
|
|
{
|
|
|
|
|
private ValueFactory binding;
|
|
|
|
|
|
|
|
|
|
public ParameterInfo Info { get; }
|
|
|
|
|
public bool HasBinding => binding != null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public BindingParameter(ParameterInfo parameter)
|
|
|
|
|
{
|
|
|
|
|
Info = parameter;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ValueFactory GetBinding()
|
|
|
|
|
{
|
|
|
|
|
return binding;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetBinding(ValueFactory valueFactory)
|
|
|
|
|
{
|
|
|
|
|
binding = valueFactory;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-31 11:01:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal class BindingResult : IBindingResult, IBindingResultAccess
|
|
|
|
|
{
|
|
|
|
|
private ResultHandler handler;
|
|
|
|
|
|
|
|
|
|
public ParameterInfo Info { get; }
|
|
|
|
|
public bool HasHandler => handler != null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public BindingResult(ParameterInfo parameter)
|
|
|
|
|
{
|
|
|
|
|
Info = parameter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ResultHandler GetHandler()
|
|
|
|
|
{
|
|
|
|
|
return handler;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetHandler(ResultHandler resultHandler)
|
|
|
|
|
{
|
|
|
|
|
handler = resultHandler;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-11 14:08:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|