Esempio n. 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"])));
 }
Esempio n. 2
0
#pragma warning disable SA1614 // Element parameter documentation must have text
        /// <summary>
        /// We will use Event Store to store our events. See https://eventstore.org
        /// </summary>
        /// <param name="parentOptions"></param>
        /// <param name="action">An Action&lt;EventStoreDotOrgOptions&gt; to configure the provided InMemoryEventStoreOptions</param>
        public static void UsingEventStoreDotOrg(this EventStoreOptions parentOptions, Action <EventStoreDotOrgOptions> action)
#pragma warning restore SA1614 // Element parameter documentation must have text
        {
            parentOptions.Services.TryAddSingleton <IEventStore, EventStoreImplementation>();

            var options = new EventStoreDotOrgOptions(parentOptions.Services);

            action.Invoke(options);
            parentOptions.Services.TryAddSingleton(options.ConnectionFactory);
        }
Esempio n. 3
0
#pragma warning disable SA1614 // Element parameter documentation must have text
        /// <summary>
        /// We will use an in-memory event store.
        /// WARNING! Any events stored in here will be lost when the executing process exits, so you
        /// probably don't want to use this in production.
        /// </summary>
        /// <param name="parentOptions"></param>
        /// <param name="action">An Action&lt;InMemoryEventStoreOptions&gt; to configure the provided InMemoryEventStoreOptions</param>
        public static void InMemory(this EventStoreOptions parentOptions, Action <InMemoryEventStoreOptions> action)
#pragma warning restore SA1614 // Element parameter documentation must have text
        {
            parentOptions.Services.TryAddSingleton <Evelyn.Core.InMemoryEventStore>();
            parentOptions.Services.TryAddSingleton <IEventStore>(sp => sp.GetRequiredService <Evelyn.Core.InMemoryEventStore>());
            parentOptions.Services.TryAddSingleton <IInMemoryEventStore>(sp => sp.GetRequiredService <Evelyn.Core.InMemoryEventStore>());

            parentOptions.Services.AddHostedService <Evelyn.Core.ReadModel.EventStream.Subscribers.InMemoryEventStoreCatchUpSubscriber>(); // TODO: move this

            action.Invoke(new InMemoryEventStoreOptions(parentOptions.Services));
        }
Esempio n. 4
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);
        }