public EventStorePersistentSubscription(IEventStoreConnection conn, IConfiguration config, EventDeserializer eventDeserializer, ILogger <EventStorePersistentSubscription> logger)
 {
     _conn = conn;
     _eventDeserializer = eventDeserializer;
     _credentials       = new UserCredentials(config["subscription_user"] ?? "admin", config["subscriptions_password"] ?? "changeit");
     _logger            = logger;
 }
        public static EventDeserializer AddEventSourcing(this IServiceCollection services, IConfiguration configuration)
        {
            var esConnection = EventStoreConnection.Create(
                configuration["eventstore"] ?? "ConnectTo=tcp://admin:changeit@localhost:1113; DefaultUserCredentials=admin:changeit;",
                ConnectionSettings.Create().KeepReconnecting());

            var serviceProvider     = services.BuildServiceProvider();
            var eventDeserializer   = new EventDeserializer();
            var subscriptionManager = new SubscriptionManager(
                esConnection,
                eventDeserializer,
                configuration,
                serviceProvider.GetRequiredService <ILogger <SubscriptionManager> >(),
                new AttendantsMongoProjection(GetMongoDb, serviceProvider.GetRequiredService <ILogger <AttendantsMongoProjection> >()));

            services.AddSingleton(esConnection);
            services.AddSingleton(eventDeserializer);
            services.AddSingleton <IEventStoreBus, EventStorePersistentSubscription>();
            services.AddSingleton <SubscriptionManager>(subscriptionManager);
            services.AddScoped <IEventStoreRepository, EventStoreRepository>();
            services.AddHostedService <EventStoreService>();
            return(eventDeserializer);

            IMongoDatabase GetMongoDb() =>
            new MongoClient(configuration["mongodb"] ?? "mongodb://localhost")
            .GetDatabase(configuration["projectionsdb"] ?? "projectionsdb");
        }
示例#3
0
 public SubscriptionManager(
     IEventStoreConnection connection,
     EventDeserializer deserializer,
     IConfiguration configuration,
     ILogger <SubscriptionManager> logger,
     params IProjection[] projections)
 {
     _connection   = connection;
     _name         = configuration["subscription_name"] ?? "default";
     _projections  = projections;
     _deserializer = deserializer;
     _logger       = logger;
 }
示例#4
0
 public EventStoreRepository(IEventStoreConnection eventStoreConnection, EventDeserializer eventDeserializer)
 {
     _eventStoreConnection = eventStoreConnection;
     _eventDeserializer    = eventDeserializer;
 }