public static IEventBusBuilder AddEventListeners(this IEventBusBuilder builder, Action <EventServiceCollectionConfigurator> configure) { if (configure == null) { throw new ArgumentNullException(nameof(configure)); } var configurator = new ServiceCollectionConfigurator(builder.Services); var wrapper = new EventServiceCollectionConfigurator(configurator); configure(wrapper); builder.Services.AddSingleton(configurator); builder.Services.AddSingleton(provider => EventBusFactory.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.EventQueueName, e => { e.LoadFrom(provider); }); })); builder.Services.AddSingleton <IHostedService, ServiceBusEventHost>(); return(builder); }
/// <summary> /// Adds the required services to the service collection, and allows consumers to be added and/or discovered /// </summary> /// <param name="collection"></param> /// <param name="configure"></param> public static IServiceCollection AddMassTransit(this IServiceCollection collection, Action <IServiceCollectionConfigurator> configure = null) { var configurator = new ServiceCollectionConfigurator(collection); configure?.Invoke(configurator); return(collection); }
/// <summary> /// Adds the required services to the service collection, and allows consumers to be added and/or discovered /// </summary> /// <param name="collection"></param> /// <param name="configure"></param> public static IServiceCollection AddMassTransit(this IServiceCollection collection, Action <IServiceCollectionConfigurator> configure = null) { if (collection.Any(d => d.ServiceType == typeof(IRegistration))) { throw new ConfigurationException( "AddMassTransit() was already called and may only be called once per container. To configure additional bus instances, refer to the documentation: https://masstransit-project.com/usage/containers/multibus.html"); } var configurator = new ServiceCollectionConfigurator(collection); configure?.Invoke(configurator); return(collection); }
/// <summary> /// Adds the required services to the service collection, and allows consumers to be added and/or discovered /// </summary> /// <param name="collection">The service collection</param> /// <param name="configure">Bus instance configuration method</param> public static IServiceCollection AddMassTransit <TBus, TBusInstance>(this IServiceCollection collection, Action <IServiceCollectionConfigurator <TBus> > configure) where TBus : class, IBus where TBusInstance : BusInstance <TBus>, TBus { if (configure == null) { throw new ArgumentNullException(nameof(configure)); } var configurator = new ServiceCollectionConfigurator <TBus, TBusInstance>(collection); configure(configurator); return(collection); }
public CommandServiceCollectionConfigurator(ServiceCollectionConfigurator serviceCollectionConfigurator) { _serviceCollectionConfigurator = serviceCollectionConfigurator ?? throw new ArgumentNullException(nameof(serviceCollectionConfigurator)); }