public ManualPipelineAdapter Register(IPipeline pipeline)
        {
            ValidatePipeline(pipeline);

            log.DebugFormat("Adding {0} to the generic specific pipelines", pipeline.GetType());

            agnosticPipelines.Register(pipeline);
            return(this);
        }
Example #2
0
        public static void AddIfNonExisting(this IPipelineCollection pipelineCollection, IPipeline pipeline)
        {
            string name = (pipeline as INamedPipeline)?.PipelineName ?? pipeline?.GetType().Name;

            if (!pipelineCollection.ContainsKey(name))
            {
                pipelineCollection.Add(name, pipeline);
            }
        }
        public ManualPipelineAdapter Register <TEvent>(IPipeline <TEvent> pipeline) where TEvent : IEvent
        {
            ValidatePipeline(pipeline);

            log.DebugFormat("Adding {0} to the type specific pipelines", pipeline.GetType());

            typeSpecificPipelines.Register(typeof(TEvent), pipeline);
            return(this);
        }
Example #4
0
        private Task <Result <TData> > ExecuteCommandAsync <TData>(IPipeline command)
        {
            var commandHandlerType = typeof(ICommandHandler <,>).MakeGenericType(command.GetType(), typeof(TData));
            var methodInfo         = commandHandlerType.GetMethod(nameof(ICommandHandler <ICommand <TData>, TData> .ExecuteAsync),
                                                                  BindingFlags.Public | BindingFlags.Instance);

            Check.NotNull(methodInfo, nameof(ICommandHandler <ICommand <TData>, TData> .ExecuteAsync));

            var commandHandler = _serviceProvider.GetService(commandHandlerType);

            Check.NotNull(commandHandler, $"command handler not found in DI container by type {commandHandlerType.FullName}");

            return((Task <Result <TData> >)methodInfo.Invoke(commandHandler, new object[] { command }));
        }
Example #5
0
        public virtual async Task <Result> ExecuteAsync(IPipeline pipeline)
        {
            var pipelineType        = typeof(IPipeline <>);
            var genericPipelineType = pipeline.GetType().GetInterfaces()
                                      .FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == pipelineType);

            if (genericPipelineType != null)
            {
                var dataType   = genericPipelineType.GetGenericArguments().First();
                var methodInfo = GetType()
                                 .GetMethods(BindingFlags.Instance | BindingFlags.Public)
                                 .Where(m => m.Name == nameof(IMediator.ExecuteAsync))
                                 .Single(m => m.IsGenericMethod)
                                 .MakeGenericMethod(dataType);

                var convertMethodInfo = GetType()
                                        .GetMethod(nameof(LocalConvert),
                                                   BindingFlags.Static | BindingFlags.NonPublic);

                Check.NotNull(convertMethodInfo, nameof(Convert));

                var convertGenericMethodInfo = convertMethodInfo.MakeGenericMethod(dataType);

                var taskResult = methodInfo.Invoke(this, new object[] { pipeline });
                return(await(Task <Result>) convertGenericMethodInfo.Invoke(null, new[] { taskResult }));
            }

            Task <Result> resultTask;

            switch (pipeline)
            {
            case ICommand command:
                resultTask = ExecuteCommandAsync(command);
                break;

            case IInternalPipelineItem internalPipelineItem:
                resultTask = ExecuteInternalPipeline(internalPipelineItem);
                break;

            default:
                resultTask = ExecutePipelineAsync(pipeline);
                break;
            }

            return(await resultTask);
        }
Example #6
0
        private Task <Result <TData> > ExecuteQueryAsync <TData>(IPipeline query)
        {
            if (query is ICacheableQuery <TData> cacheableQuery)
            {
                return(ExecuteCacheableQueryAsync(cacheableQuery));
            }

            var queryHandlerType = typeof(IQueryHandler <,>).MakeGenericType(query.GetType(), typeof(TData));
            var methodInfo       = queryHandlerType.GetMethod(nameof(IQueryHandler <IQuery <TData>, TData> .ExecuteAsync),
                                                              BindingFlags.Public | BindingFlags.Instance);

            Check.NotNull(methodInfo, nameof(IQueryHandler <IQuery <TData>, TData> .ExecuteAsync));

            var queryHandler = _serviceProvider.GetService(queryHandlerType);

            if (queryHandler == null)
            {
                _logger.LogError($"Handler not found for type {queryHandlerType.FullName}");
                return(Task.FromResult(new Result <TData>(SystemErrorCodes.SystemError.AsError())));
            }

            return((Task <Result <TData> >)methodInfo.Invoke(queryHandler, new object[] { query }));
        }
 internal static Type[] GetPipelineGenericArguments(this IPipeline pipeline)
 {
     return(pipeline.GetType().GetPipelineGenericArguments());
 }
 public static string Description(this IPipeline pipeline)
 {
     return(pipeline.GetType().GetDescription());
 }
 public static string Name(this IPipeline pipeline)
 {
     return(pipeline.GetType().GetName());
 }
Example #10
0
 public static void Add(this IPipelineCollection pipelineCollection, IPipeline pipeline) =>
 pipelineCollection.Add((pipeline as INamedPipeline)?.PipelineName ?? pipeline?.GetType().Name, pipeline);
Example #11
0
        private Task <Result> ExecutePipelineAsync(IPipeline pipeline)
        {
            var pipelineItemHandlerType = typeof(IPipelineItemHandler <>).MakeGenericType(pipeline.GetType());
            var methodInfo = pipelineItemHandlerType.GetMethod(nameof(IPipelineItemHandler <IPipeline> .ExecuteAsync),
                                                               BindingFlags.Public | BindingFlags.Instance);

            Check.NotNull(methodInfo, nameof(IPipelineItemHandler <IPipeline> .ExecuteAsync));

            var pipelineItemHandler = _serviceProvider.GetService(pipelineItemHandlerType);

            Check.NotNull(pipelineItemHandler, $"handler not found in DI container by type {pipelineItemHandlerType.FullName}");

            return((Task <Result>)methodInfo.Invoke(pipelineItemHandler, new object[] { pipeline }));
        }