public static IMessageHandlerBuilder AddAsyncMessaging(this IServiceCollection services, IConfiguration configuration) { var subscription = configuration.GetValue("subscription_name", "default"); var options = new AsyncMessagingOptions { Subscription = subscription }; var registry = new MessageHandlerRegistry(); var factory = new MessageHandlerFactory(services); services .AddSingleton(options) .AddSingleton(registry) .AddSingleton(factory) .AddSingleton <MessageDispatcherService>() .AddHostedService <AsyncMessagingService>(); return(new MessageHandlerBuilder(services, registry)); }
public static IMessageHandlerBuilder AddAsyncMessaging(this IServiceCollection services, IConfiguration configuration) { var messageBroker = configuration.GetValue("messagebroker", "host=localhost;username=guest;password=guest;publisherConfirms=true"); var subscription = configuration.GetValue("subscription", "default"); var options = new AsyncMessagingOptions { Subscription = subscription }; var registry = new MessageHandlerRegistry(); var factory = new MessageHandlerFactory(services); services .AddSingleton(options) .AddSingleton <IBus>(RabbitHutch.CreateBus(messageBroker)) .AddSingleton(registry) .AddSingleton(factory) .AddSingleton <MessageDispatcherService>() .AddHostedService <AsyncMessagingService>() .AddHostedService <OutboxProcessor>(); return(new MessageHandlerBuilder(services, registry)); }