Exemple #1
0
 public static IServiceCollection AddEasyEventSourcing <TAggregateRoot>(this IServiceCollection services,
                                                                        IConfiguration configuration) where TAggregateRoot : IAggregate
 {
     configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
     return(services.AddEasyEventSourcing <TAggregateRoot>(EventStoreOptions.Create(
                                                               configuration["EVENT_STORE"],
                                                               configuration["EVENT_STORE_API"])));
 }
Exemple #2
0
        public static IServiceCollection AddEasyEventSourcing <TAggregateRoot>(this IServiceCollection services,
                                                                               EventStoreOptions options = null) where TAggregateRoot : IAggregate
        {
            services = services ?? throw new ArgumentNullException(nameof(services));
            options  = options ?? EventStoreOptions.Create();

            var connection        = EventStoreConnectionFactory.Create(options.ConnectionString);
            var eventDeserializer = new EventDeserializer(typeof(TAggregateRoot).GetTypeInfo().Assembly);
            var projections       = new EventStoreProjectionsClient(options);

            services.AddSingleton(connection);
            services.AddSingleton(eventDeserializer);

            services.AddSingleton <IEventStoreProjections>(projections);
            services.AddSingleton <IEventStoreBus>(new EventStoreSubscription(connection, options, eventDeserializer, projections));

            services.AddTransient <IRepository, EventStoreRepository>();
            services.AddTransient <IEventStore, EventStoreRepository>();

            return(services);
        }