Exemplo n.º 1
0
        public void AddServiceConfiguration_configures_given_service(NybusConfigurator sut, Type serviceType, IServiceCollection services)
        {
            sut.AddServiceConfiguration(svc => svc.AddSingleton(serviceType));

            sut.ConfigureServices(services);

            Mock.Get(services).Verify(p => p.Add(It.Is <ServiceDescriptor>(sd => sd.ServiceType == serviceType)));
        }
Exemplo n.º 2
0
        public void AddServiceConfiguration_invokes_configuration_delegate(NybusConfigurator sut, IServiceCollection services, Action <IServiceCollection> configurationDelegate)
        {
            sut.AddServiceConfiguration(configurationDelegate);

            sut.ConfigureServices(services);

            Mock.Get(configurationDelegate).Verify(p => p(services), Times.Once);
        }
Exemplo n.º 3
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);
        }