Beispiel #1
0
        public static IBareBonesBuilder AddMessageOutbox(this IBareBonesBuilder builder, Action <IMessageOutboxBuilder> outboxConfigurar, string sectionName = SectionName)
        {
            if (string.IsNullOrWhiteSpace(sectionName))
            {
                sectionName = SectionName;
            }

            builder.RegisterModule <OutboxModule>();

            var options = builder.Configuration.GetOptions <OutboxOptions>(sectionName);

            builder.Services.AddSingleton(options);
            var outboxBuilder = new MessageOutboxBuilder(builder, options);

            if (outboxConfigurar is null)
            {
                outboxBuilder.AddInMemory();
            }
            else
            {
                outboxConfigurar(outboxBuilder);
            }

            if (!options.Enabled)
            {
                return(builder);
            }

            builder.Services.AddHostedService <OutboxHostedService>();


            return(builder);
        }
Beispiel #2
0
        public static IBareBonesBuilder AddCommandGateway(this IBareBonesBuilder builder,
                                                          Action <ICommandGatewayBuilder> gateway)
        {
            builder.Services.AddSingleton <ICommandGateway, CommandGateway>();
            builder.Services.AddScoped <ICommandGatewayFiltersExecutor, CommandGatewayFiltersExecutor>();

            var gatewayBuilder = new CommandGatewayBuilder(builder);

            gateway?.Invoke(gatewayBuilder);

            builder.Services.AddSingleton <ICommandGatewayBuilder>(gatewayBuilder);
            return(builder.RegisterModule <ICommandGateway>());
        }
Beispiel #3
0
        public static IBareBonesBuilder AddCommandDispatcher(this IBareBonesBuilder builder,
                                                             Action <ICommandDispatcherBuilder> dispatcher)
        {
            builder.Services.AddSingleton <ICommandDispatcher, CommandDispatcher>();
            builder.Services.AddScoped <IDispatchFiltersExecutor, DispatchFiltersExecutor>();

            var commandDispatcherBuilder = new CommandDispatcherBuilder(builder);

            commandDispatcherBuilder.AddInProcessDispatcher();

            dispatcher?.Invoke(commandDispatcherBuilder);

            builder.Services.AddSingleton <ICommandDispatcherBuilder>(commandDispatcherBuilder);
            return(builder.RegisterModule <ICommandDispatcher>());
        }
Beispiel #4
0
        public static IBareBonesBuilder AddQueryGateway(this IBareBonesBuilder builder)
        {
            builder.Services.AddSingleton <IQueryGateway, QueryGateway>();

            builder.Services.Scan(selector =>
                                  selector.FromAssemblies(AppDomain.CurrentDomain.GetAssemblies())
                                  .AddClasses(c => c.AssignableTo(typeof(IQueryHandler <,>)))
                                  .AsImplementedInterfaces()
                                  .WithTransientLifetime()
                                  .AddClasses(c => c.AssignableTo(typeof(IQueryHandlerFilter)))
                                  .AsImplementedInterfaces()
                                  .WithTransientLifetime());

            return(builder.RegisterModule <IQueryGateway>());
        }