public static IEventStoreConnection Create(EventStoreLocation eventStoreLocation, IEventStoreConfiguration configuration)
        {
            IEventStore eventStore;

            if (eventStoreLocation == EventStoreLocation.Embedded)
            {
                eventStore = new EmbeddedEventStore();
            }
            else
            {
                eventStore = new ExternalEventStore(EventStoreUri.FromConfig(configuration));
            }

            return(eventStore.Connection);
        }
        public static IWebHostBuilder UseEventStore(this IWebHostBuilder hostBuilder)
        {
            var configuration        = new EventStoreConfiguration(ServiceConstants.EventStoreUrl);
            var eventStoreConnection = new ExternalEventStore(EventStoreUri.FromConfig(configuration)).Connection;

            eventStoreConnection.ConnectAsync().Wait();

            var monitor          = new ConnectionStatusMonitor(eventStoreConnection);
            var eventStoreStream = monitor.GetEventStoreConnectedStream(eventStoreConnection);

            hostBuilder.ConfigureServices((services) =>
            {
                services.Add(new ServiceDescriptor(typeof(IEventStoreConnection), eventStoreConnection));
                services.Add(new ServiceDescriptor(typeof(IObservable <IConnected <IEventStoreConnection> >), eventStoreStream));
            });

            return(hostBuilder);
        }