public static void AddEventStore(this IServiceCollection services) { IConfiguration configuration; using (var serviceProvider = services.BuildServiceProvider()) { configuration = serviceProvider.GetService <IConfiguration>(); } var eventStoreConfig = configuration.GetSection("EventStore").Get <EventStoreConfig>(); var userCrendetials = new global::EventStore.ClientAPI.SystemData.UserCredentials(eventStoreConfig.Username, eventStoreConfig.Password); var connectionSettings = ConnectionSettings.Create(); connectionSettings.SetDefaultUserCredentials(userCrendetials); connectionSettings.KeepReconnecting(); var eventStoreConnection = EventStoreConnection.Create( connectionSettings: connectionSettings, uri: eventStoreConfig.Host, connectionName: "Meeting.Groups.Consumer"); eventStoreConnection.ConnectAsync().GetAwaiter().GetResult(); services.AddSingleton(eventStoreConnection); services.AddHostedService <CitiesEventStoreHostedService>(); services.AddHostedService <TopicsEventStoreHostedService>(); services.AddHostedService <UsersEventStoreHostedService>(); }
public static void AddEventStore(this IServiceCollection services, IConfiguration configuration) { var eventStoreConfig = configuration.GetSection("EventStore").Get <EventStoreConfig>(); var userCrendetials = new global::EventStore.ClientAPI.SystemData.UserCredentials(eventStoreConfig.Username, eventStoreConfig.Password); var connectionSettings = ConnectionSettings.Create(); connectionSettings.SetDefaultUserCredentials(userCrendetials); connectionSettings.KeepReconnecting(); var eventStoreConnection = EventStoreConnection.Create( connectionSettings: connectionSettings, uri: eventStoreConfig.Host, connectionName: "Meeting.Events.API"); eventStoreConnection.ConnectAsync().GetAwaiter().GetResult(); services.AddSingleton(eventStoreConnection); }