Пример #1
0
        public void AddSubscription_configures(NybusConfigurator sut, ISubscriptionBuilder subscriptionBuilder, Action <ISubscriptionBuilder> subscriptionDelegate)
        {
            sut.AddSubscription(subscriptionDelegate);

            sut.ConfigureBuilder(subscriptionBuilder);

            Mock.Get(subscriptionDelegate).Verify(p => p(subscriptionBuilder), Times.Once);
        }
Пример #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);
        }