Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public ICqrsRuntime Build(
            AssemblyScanConfig[] assembliesWithCommandHandlers,
            AssemblyScanConfig[] assembliesWithEventHandlers)
        {
            var commandHandlers = OnResolveCommandHandlers(assembliesWithCommandHandlers);
            var eventHandlers   = OnResolveEventHandlers(assembliesWithEventHandlers);

            return(new CqrsRuntime
                   (
                       CommandBusFactory.Invoke(commandHandlers),
                       EventStoreFactory.Invoke(),
                       EventApplierFactory.Invoke(),
                       EventPublisherFactory.Invoke(eventHandlers)
                   ));
        }
        /// <summary>
        /// Add CommandBus related stuff to IoC
        /// </summary>
        /// <param name="services">The services</param>
        /// <param name="configureSettings">Action to be able to configure the command bus</param>
        /// <returns></returns>
        public static ICommandBusBuilder AddCommandBus(this IServiceCollection services, Action <ServiceBusSettings> configureSettings = null)
        {
            var settings = new ServiceBusSettings();

            configureSettings?.Invoke(settings);

            var builder = new CommandBusBuilder(services, settings);

            services.AddSingleton(settings);
            services.AddMassTransit();
            services.AddSingleton(provider => CommandBusFactory.Build(cfg =>
            {
                cfg.Host(new Uri(settings.ConnectionString), h =>
                {
                    h.Username(settings.UserName);
                    h.Password(settings.Password);
                });
            }));

            builder.AddCommandPublisher();
            return(builder);
        }
Ejemplo n.º 4
0
        public Sword()
        {
            this.commandBusClient = CommandBusFactory.CreateCommandBus();

            this._proxy = CommandBusILEmitAdapter.Create <T>(this.commandBusClient);
        }