예제 #1
0
        private static void TryAddCommandPipeline(IServiceCollection services, Type contract, ServiceLifetime lifetime)
        {
            var commandType  = contract.GenericTypeArguments[0];
            var pipelineType = PipelineTypes.Command.MakeGenericType(commandType);

            if (NeedCreatePipeline(services, pipelineType, lifetime))
            {
                services.Add(new ServiceDescriptor(
                                 pipelineType,
                                 PipelineActivators.GetCommandPipelineActivator(commandType),
                                 lifetime));
            }
        }
예제 #2
0
        private static void TryAddQueryPipeline(IServiceCollection services, Type contract, ServiceLifetime lifetime)
        {
            var queryType    = contract.GenericTypeArguments[0];
            var resultType   = contract.GenericTypeArguments[1];
            var pipelineType = PipelineTypes.Query.MakeGenericType(queryType, resultType);

            if (NeedCreatePipeline(services, pipelineType, lifetime))
            {
                services.Add(new ServiceDescriptor(
                                 pipelineType,
                                 PipelineActivators.GetQueryPipelineActivator(queryType, resultType),
                                 lifetime));
            }
        }
예제 #3
0
        public static IServiceCollection AddNotificationProcessor <TProcessor>(this IServiceCollection services,
                                                                               ServiceLifetime lifetime = ServiceLifetime.Singleton)
        {
            var implementation      = typeof(TProcessor);
            var processorInterfaces = PipelineTypes.NotificationProcessorTypes;

            var descriptor = BuildProcessorDescriptor(implementation, processorInterfaces, lifetime);

            services.Add(descriptor);

            var notificationType = descriptor.ServiceType.GenericTypeArguments[0];
            var pipelineType     = PipelineTypes.Notification.MakeGenericType(notificationType);

            if (NeedCreatePipeline(services, pipelineType, lifetime))
            {
                services.Add(new ServiceDescriptor(
                                 pipelineType,
                                 PipelineActivators.GetNotificationPipelineActivator(notificationType),
                                 lifetime));
            }

            return(services);
        }