예제 #1
0
        public static IServiceCollection AddMessageOutbox(this IServiceCollection services,
                                                          Action <IMessageOutboxConfigurator> configure = null, string sectionName = SectionName)
        {
            if (string.IsNullOrWhiteSpace(sectionName))
            {
                sectionName = SectionName;
            }

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

            services.AddSingleton(options);
            var configurator = new MessageOutboxConfigurator(services, options);

            if (configure is null)
            {
                configurator.AddInMemory();
            }
            else
            {
                configure(configurator);
            }

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

            services.AddHostedService <OutboxProcessor>();

            return(services);
        }
예제 #2
0
        public static IConveyBuilder AddMessageOutbox(this IConveyBuilder builder,
                                                      Action <IMessageOutboxConfigurator> configure = null, string sectionName = SectionName)
        {
            if (string.IsNullOrWhiteSpace(sectionName))
            {
                sectionName = SectionName;
            }

            if (!builder.TryRegister(RegistryName))
            {
                return(builder);
            }

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

            builder.Services.AddSingleton(options);
            var configurator = new MessageOutboxConfigurator(builder, options);

            if (configure is null)
            {
                configurator.AddInMemory();
            }
            else
            {
                configure(configurator);
            }

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

            builder.Services.AddHostedService <OutboxProcessor>();

            return(builder);
        }