public static ISIOInfrastructureBuilder AddEntityFrameworkCoreSqlServer(this ISIOInfrastructureBuilder source, Action <SIOEntityFrameworkCoreSqlServerOptions> builderAction)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            source.AddEntityFrameworkCore();

            var sqlBuilder = new SIOEntityFrameworkCoreSqlServerOptions();

            builderAction(sqlBuilder);

            source.AddEntityFrameworkCoreStore(o => IntializeStoreOptions(sqlBuilder, o));

            if (!string.IsNullOrWhiteSpace(sqlBuilder.ProjectionConnectionString))
            {
                source.Services.AddDbContext <SIOProjectionDbContext>(options =>
                {
                    options.UseSqlServer(sqlBuilder.ProjectionConnectionString, sqlBuilder.ProjectionOptions);
                });
            }

            return(source);
        }
        public static ISIOInfrastructureBuilder AddQueries(this ISIOInfrastructureBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.AddScoped <IQueryDispatcher, DefaultQueryDispatcher>();

            return(builder);
        }
        public static ISIOInfrastructureBuilder AddAzureStorage(this ISIOInfrastructureBuilder builder, Action <AzureStorageBlobOptions> options)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }


            builder.Services.Configure(options);
            builder.Services.AddScoped <IFileClient, AzureFileClient>();

            return(builder);
        }
        public static ISIOInfrastructureBuilder AddEvents(this ISIOInfrastructureBuilder builder, Action <EventOptions> optionsAction)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.AddScoped <IEventDispatcher, DefaultEventDispatcher>();

            builder.Services.Configure(optionsAction);

            return(builder);
        }
        public static ISIOInfrastructureBuilder AddBackgroundProcessing(this ISIOInfrastructureBuilder builder, Action <BackgroundProcessorOptions> optionsAction)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.Configure(optionsAction);

            builder.Services.AddHostedService <BackgroundTaskProcessor>();
            builder.Services.AddSingleton <IBackgroundTaskQueue, BackgroundTaskQueue>();

            return(builder);
        }
コード例 #6
0
        public static ISIOInfrastructureBuilder AddAzureServiceBus(this ISIOInfrastructureBuilder builder, Action <ServiceBusOptions> optionsAction)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.Configure(optionsAction);

            builder.Services.AddScoped <IEventBusPublisher, AzureServiceBus>();
            builder.Services.AddScoped <IEventBusConsumer, AzureServiceBus>();
            builder.Services.AddScoped <IMessageFactory, DefaultMessageFactory>();
            builder.Services.AddScoped <ISubscriptionClientFactory, DefaultSubscriptionClientFactory>();
            builder.Services.AddScoped <ISubscriptionClientManager, DefaultSubscriptionClientManager>();
            builder.Services.AddScoped <ITopicClientFactory, DefaultTopicClientFactory>();
            builder.Services.AddScoped <ITopicMessageReceiver, DefaultTopicMessageReceiver>();
            builder.Services.AddScoped <IEventContextFactory, DefaultEventContextFactory>();
            builder.Services.AddScoped <ITopicMessageSender, DefaultTopicMessageSender>();
            builder.Services.AddScoped <IServiceBusManagementClient, ServiceBusManagementClient>();
            builder.Services.AddScoped(sp =>
            {
                var options = sp.GetRequiredService <IOptions <ServiceBusOptions> >();
                var connectionStringBuilder = new ServiceBusConnectionStringBuilder(options.Value.ConnectionString);

                if (string.IsNullOrEmpty(connectionStringBuilder.EntityPath) && options.Value.Topic == null)
                {
                    throw new InvalidOperationException($"Azure service bus connection string doesn't contain an entity path and 'UseTopic(...)' has not been called. Either include the entity path in the connection string or by calling 'UseTopic(...)' during startup when configuring Azure Service Bus.");
                }

                if (options.Value.Topic != null)
                {
                    connectionStringBuilder.EntityPath = options.Value.Topic.Name;
                }

                if (!string.IsNullOrEmpty(connectionStringBuilder.EntityPath) && options.Value.Topic == null)
                {
                    options.Value.UseTopic(t => t.WithName(connectionStringBuilder.EntityPath));
                }

                return(connectionStringBuilder);
            });
            builder.Services.AddScoped(sp =>
            {
                var connectionStringBuilder = sp.GetRequiredService <ServiceBusConnectionStringBuilder>();

                return(new ManagementClient(connectionStringBuilder));
            });

            return(builder);
        }
コード例 #7
0
        public static ISIOInfrastructureBuilder AddEntityFrameworkCore(this ISIOInfrastructureBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.AddScoped <ICommandStore, EntityFrameworkCoreCommandStore>();
            builder.Services.AddScoped <IQueryStore, EntityFrameworkCoreQueryStore>();
            builder.Services.AddScoped <IEventContextFactory, DefaultEventContextFactory>();
            builder.Services.AddScoped <IEventModelFactory, DefaultEventModelFactory>();
            builder.Services.AddScoped <ISIOProjectionDbContextFactory, SIOProjectionDbContextFactory>();

            return(builder);
        }
        public static ISIOInfrastructureBuilder AddJsonSerializers(this ISIOInfrastructureBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.AddSingleton <ICommandDeserializer, JsonCommandDeserializer>();
            builder.Services.AddSingleton <ICommandSerializer, JsonCommandSerializer>();
            builder.Services.AddSingleton <IEventDeserializer, JsonEventDeserializer>();
            builder.Services.AddSingleton <IEventSerializer, JsonEventSerializer>();
            builder.Services.AddSingleton <IQueryDeserializer, JsonQueryDeserializer>();
            builder.Services.AddSingleton <IQuerySerializer, JsonQuerySerializer>();
            builder.Services.AddSingleton <IProjectionDeserializer, JsonProjectionDeserializer>();
            builder.Services.AddSingleton <IProjectionSerializer, JsonProjectionSerializer>();

            return(builder);
        }
コード例 #9
0
        public static ISIOInfrastructureBuilder AddEntityFrameworkCoreStore(this ISIOInfrastructureBuilder builder, Action <EntityFrameworkCoreStoreOptions> options)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var entityFrameworkCoreStoreOptions = new EntityFrameworkCoreStoreOptions();

            options(entityFrameworkCoreStoreOptions);

            foreach (var(storeType, projectorOptions) in entityFrameworkCoreStoreOptions.Stores)
            {
                builder.Services.RegisterStore(storeType, projectorOptions);
            }

            return(builder);
        }
        public static ISIOInfrastructureBuilder AddMessagePackSerialization(this ISIOInfrastructureBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.AddScoped <ICommandDeserializer, MessagePackCommandDeserializer>();
            builder.Services.AddScoped <ICommandSerializer, MessagePackCommandSerializer>();
            builder.Services.AddScoped <IEventDeserializer, MessagePackEventDeserializer>();
            builder.Services.AddScoped <IEventSerializer, MessagePackEventSerializer>();
            builder.Services.AddScoped <IQueryDeserializer, MessagePackQueryDeserializer>();
            builder.Services.AddScoped <IQuerySerializer, MessagePackQuerySerializer>();

            var resolver = CompositeResolver.Create(
                new IMessagePackFormatter[]
            {
                NativeDateTimeArrayFormatter.Instance,
                NativeDateTimeFormatter.Instance,
                NativeDecimalFormatter.Instance,
                NativeGuidFormatter.Instance,
                TypelessFormatter.Instance,
            },
                new IFormatterResolver[]
            {
                NativeDateTimeResolver.Instance,
                NativeDecimalResolver.Instance,
                NativeGuidResolver.Instance,
                ContractlessStandardResolverAllowPrivate.Instance,
                TypelessObjectResolver.Instance,
                StandardResolverAllowPrivate.Instance
            });

            var options = MessagePackSerializerOptions.Standard
                          .WithCompression(MessagePackCompression.None)
                          .WithResolver(resolver);

            builder.Services.AddSingleton(options);

            return(builder);
        }
コード例 #11
0
        public static ISIOInfrastructureBuilder AddRabbitMq(this ISIOInfrastructureBuilder builder, Action <RabbitMqOptions> optionsAction)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }


            builder.Services.Configure(optionsAction);

            builder.Services.AddScoped <IMessageFactory, DefaultMessageFactory>();
            builder.Services.AddScoped <IEventBusPublisher, RabbitMqEventBus>();
            builder.Services.AddScoped <IEventBusConsumer, RabbitMqEventBus>();
            builder.Services.AddSingleton <RabbitMqConnectionPool>();
            builder.Services.AddSingleton <IRabbitMqConnectionFactory, RabbitMqConnectionFactory>();
            builder.Services.AddScoped <IQueueMessageSender, DefaultQueueMessageSender>();
            builder.Services.AddSingleton <IQueueMessageReceiver, DefaultQueueMessageReceiver>();
            builder.Services.AddScoped <ISubscriptionManager, DefaultSubscriptionManager>();
            builder.Services.AddScoped <IRabbitMqManagementClient, RabbitMqManagementClient>();
            builder.Services.AddHttpClient <IRabbitMqManagementApiClient, RabbitMqManagementApiClient>();
            builder.Services.AddSingleton <IEventContextFactory, DefaultEventContextFactory>();

            return(builder);
        }
 public static ISIOInfrastructureBuilder AddConnectionPool <TConnection, TConnectionFactory>(this ISIOInfrastructureBuilder builder)
     where TConnection : IConnection
     where TConnectionFactory : class, IConnectionFactory <TConnection>
 {
     builder.Services.AddSingleton <IConnectionFactory <TConnection>, TConnectionFactory>();
     builder.Services.AddSingleton <IConnectionPool <TConnection>, ConnectionPool <TConnection> >();
     return(builder);
 }