コード例 #1
0
        public void Configure_(NybusConfigurator sut, IServiceProvider serviceProvider, INybusConfiguration configuration, Action <INybusConfiguration> configurationDelegate)
        {
            sut.Configure(configurationDelegate);

            sut.CustomizeConfiguration(serviceProvider, configuration);

            Mock.Get(configurationDelegate).Verify(p => p(configuration));
        }
コード例 #2
0
        public static IServiceCollection AddNybus(this IServiceCollection services, Action <INybusConfigurator> configure)
        {
            var configurator = new NybusConfigurator();

            configurator.RegisterErrorFilterProvider <RetryErrorFilterProvider>();
            configurator.RegisterErrorFilterProvider <DiscardErrorFilterProvider>();

            services.AddSingleton <DiscardErrorFilter>();

            configure(configurator);

            services.AddSingleton(sp =>
            {
                var loggerFactory = sp.GetRequiredService <ILoggerFactory>();
                var builder       = new NybusHostBuilder(loggerFactory);

                return(builder);
            });

            services.AddSingleton <INybusHostConfigurationFactory, NybusHostConfigurationFactory>();

            services.AddSingleton(sp =>
            {
                var factory = sp.GetRequiredService <INybusHostConfigurationFactory>();
                var options = sp.GetRequiredService <NybusHostOptions>();

                var configuration = factory.CreateConfiguration(options);

                configurator.CustomizeConfiguration(sp, configuration);

                return(configuration);
            });

            services.AddSingleton(sp =>
            {
                var options = new NybusHostOptions();

                configurator.Configuration?.Bind(options);

                return(options);
            });

            services.AddSingleton <IMessageDescriptorStore, MessageDescriptorStore>();

            configurator.ConfigureServices(services);

            services.AddSingleton(sp =>
            {
                var engine        = sp.GetRequiredService <IBusEngine>();
                var builder       = sp.GetRequiredService <NybusHostBuilder>();
                var configuration = sp.GetRequiredService <NybusConfiguration>();

                configurator.ConfigureBuilder(builder);

                return(builder.BuildHost(engine, sp, configuration));
            });

            services.AddSingleton <IBusHost>(sp => sp.GetRequiredService <NybusHost>());

            services.AddSingleton <IBus>(sp => sp.GetRequiredService <NybusHost>());

            return(services);
        }