Example #1
0
        static void Main(string[] args)
        {
            var builder       = new ConfigurationBuilder().AddEnvironmentVariables();
            var configuration = builder.Build();

            Console.WriteLine("Starting Event Store Quiz Setup.");

            var options     = EventStoreOptions.Create(configuration);
            var projections = new EventStoreProjectionsClient(options);

            Policy.Handle <Exception>()
            .WaitAndRetryAsync(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))
            .ExecuteAsync(async() => await projections.CreateAsync(Projections.QuestionAnswers))
            .Wait();

            Console.WriteLine("Event Store Quiz Setup Done!");
        }
Example #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);
        }