예제 #1
0
        public async Task Invoke(IMessageContext context, MiddlewareDelegate next)
        {
            using (var scope = this.dependencyResolver.CreateScope())
            {
                await Task.WhenAll(
                    this.configuration
                    .HandlerMapping
                    .GetHandlersTypes(context.Message.GetType())
                    .Select(t =>
                            HandlerExecutor
                            .GetExecutor(context.Message.GetType())
                            .Execute(
                                scope.Resolver.Resolve(t),
                                context,
                                context.Message)))
                .ConfigureAwait(false);
            }

            await next(context);
        }
예제 #2
0
        public async Task Invoke(IMessageContext context, MiddlewareDelegate next)
        {
            using (var scope = this.dependencyResolver.CreateScope())
            {
                var handlerType = this.configuration.HandlerMapping.GetHandlerType(context.Message.GetType());

                if (handlerType == null)
                {
                    return;
                }

                var handler = scope.Resolver.Resolve(handlerType);

                await HandlerExecutor
                .GetExecutor(context.Message.GetType())
                .Execute(
                    handler,
                    context,
                    context.Message)
                .ConfigureAwait(false);
            }

            await next(context);
        }