private async Task ConnectToHandler(TContext context, CancellationToken cancellationToken) { var handlerBindings = PipeHelper.GetHandlerBindings(context, false); foreach (var handlerBinding in handlerBindings) { var handlerType = handlerBinding.HandlerType; var messageType = context.Message.GetType(); var handleMethod = handlerType.GetRuntimeMethods().Single(m => PipeHelper.IsHandleMethod(m, messageType)); var handler = (_resolver == null) ? Activator.CreateInstance(handlerType) : _resolver.Resolve(handlerType); var task = (Task)handleMethod.Invoke(handler, new object[] { context, cancellationToken }); await task.ConfigureAwait(false); } }
private async Task ConnectToHandler(TContext context, CancellationToken cancellationToken) { var handlerBindings = PipeHelper.GetHandlerBindings(context, true, _messageHandlerRegistry); if (handlerBindings.Count() > 1) { throw new MoreThanOneHandlerException(context.Message.GetType()); } var handlerBinging = handlerBindings.Single(); var handlerType = handlerBinging.HandlerType; var messageType = context.Message.GetType(); var handleMethod = handlerType.GetRuntimeMethods() .Single(m => PipeHelper.IsHandleMethod(m, messageType)); var handler = (_resolver == null) ? Activator.CreateInstance(handlerType) : _resolver.Resolve(handlerType); var task = (Task)handleMethod.Invoke(handler, new object[] { context, cancellationToken }); await task.ConfigureAwait(false); }
private async Task <object> ConnectToHandler(TContext context, CancellationToken cancellationToken) { var handlers = PipeHelper.GetHandlerBindings(context, true); if (handlers.Count() > 1) { throw new MoreThanOneHandlerException(context.Message.GetType()); } var binding = handlers.Single(); var handlerType = binding.HandlerType; var messageType = context.Message.GetType(); var handleMethod = handlerType.GetRuntimeMethods().Single(m => PipeHelper.IsHandleMethod(m, messageType)); var handler = (_resolver == null) ? Activator.CreateInstance(handlerType) : _resolver.Resolve(handlerType); var task = (Task)handleMethod.Invoke(handler, new object[] { context, cancellationToken }); await task.ConfigureAwait(false); return(task.GetType().GetTypeInfo().GetDeclaredProperty("Result").GetValue(task)); }