예제 #1
0
        /// <summary>
        /// Creates EventStoreDB catch-up subscription service for a given stream
        /// </summary>
        /// <param name="client"></param>
        /// <param name="checkpointStore">Checkpoint store instance</param>
        /// <param name="eventSerializer">Event serializer instance</param>
        /// <param name="eventHandlers">Collection of event handlers</param>
        /// <param name="options">Subscription options</param>
        /// <param name="loggerFactory">Optional: logger factory</param>
        /// <param name="measure">Optional: gap measurement for metrics</param>
        public StreamSubscription(
            EventStoreClient client,
            StreamSubscriptionOptions options,
            ICheckpointStore checkpointStore,
            IEnumerable <IEventHandler> eventHandlers,
            IEventSerializer?eventSerializer = null,
            ILoggerFactory?loggerFactory     = null,
            ISubscriptionGapMeasure?measure  = null
            ) : base(client, options, checkpointStore, eventHandlers, eventSerializer, loggerFactory, measure)
        {
            Ensure.NotEmptyString(options.StreamName, nameof(options.StreamName));

            _options = options;
        }
예제 #2
0
        public static IServiceCollection AddStreamSubscription(this IServiceCollection services, StreamSubscriptionOptions options)
        {
            services.AddSubscription(ConfigureSubscription);
            return(services);

            StreamSubscription ConfigureSubscription(IServiceProvider provider)
            {
                var client = provider.GetService <EventStoreClient>() ?? CreateClient();

                return(new StreamSubscription(
                           client,
                           options,
                           provider.GetRequiredService <ICheckpointStore>(),
                           provider.GetServices <IEventHandler>(),
                           provider.GetService <IEventSerializer>(),
                           provider.GetService <ILoggerFactory>(),
                           provider.GetService <SubscriptionGapMeasure>()
                           ));

                EventStoreClient CreateClient()
                {
                    var settings = provider.GetService <EventStoreClientSettings>();

                    return(settings == null
                        ? throw new InvalidOperationException(
                               "Unable to resolve both EventStoreClient and EventStoreClientSettings"
                               )
                        : new EventStoreClient(settings));
                }
            }
        }