Exemplo n.º 1
0
        public static void AddCommandRequestClient <TRequest, TResponse>(this IServiceCollection services, IConfiguration configuration)
            where TRequest : class
            where TResponse : class
        {
            var settings = new MassTransitSettings();
            var section  = configuration.GetSection("MassTransitSettings");

            section.Bind(settings);

            services.AddScoped <IRequestClient <TRequest, TResponse> >
            (
                x => new MessageRequestClient <TRequest, TResponse>
                (
                    x.GetRequiredService <IBusControl>(),
                    new Uri(settings.AzureServiceBusUrl + TypeName <TRequest>()),
                    TimeSpan.FromSeconds(settings.RequestTimeout),
                    TimeSpan.FromSeconds(settings.RequestTimeToLive)
                )
            );
        }
Exemplo n.º 2
0
        public static void ConfigureMassTransit(this IServiceCollection services, Action <IServiceBusBusFactoryConfigurator>[] configurators, IConfiguration configuration)
        {
            var settings = new MassTransitSettings();
            var section  = configuration.GetSection("MassTransitSettings");

            section.Bind(settings);
            services.Configure <MassTransitSettings>(section);

            var azureServiceBus = Bus.Factory.CreateUsingAzureServiceBus(internalConfigurator =>
            {
                configurators.ToList().ForEach(configurator =>
                {
                    configurator(internalConfigurator);
                });

                internalConfigurator.Host(settings.AzureServiceBusConnectionString);
            });

            azureServiceBus.Start();

            services.AddSingleton(azureServiceBus);

            services.AddScoped <IMassTransitService, MassTransitService>();
        }