public static ICommandBusBuilder AddCommandListeners(this ICommandBusBuilder builder, Action <CommandServiceCollectionConfigurator> configure) { if (configure == null) { throw new ArgumentNullException(nameof(configure)); } var configurator = new ServiceCollectionConfigurator(builder.Services); var wrapper = new CommandServiceCollectionConfigurator(configurator); configure(wrapper); builder.Services.AddSingleton(configurator); builder.Services.AddSingleton(provider => CommandBusFactory.Build(cfg => { var host = cfg.Host(new Uri(builder.Settings.ConnectionString), h => { h.Username(builder.Settings.UserName); h.Password(builder.Settings.Password); }); cfg.ReceiveEndpoint(host, wrapper.CommandQueueName, e => { e.LoadFrom(provider); }); })); builder.Services.AddSingleton <IHostedService, ServiceBusCommandHost>(); return(builder); }
public static ICommandBusBuilder AddCommandPublisher(this ICommandBusBuilder builder) { builder.Services.AddScoped <ICommandPublisher, CommandPublisher>(); return(builder); }