/// <summary>
        /// Adds <see cref="MemoryCacheBackgroundCommandEventRepository"/> to store events using <see cref="IMemoryCache"/>.
        /// Do not forget to register a <see cref="IMemoryCache"/> implementation.
        /// </summary>
        /// <param name="builder">The <see cref="BackgroundBuilder"/>.</param>
        /// <param name="expiration">The expiration time of events. Defaults to 10 minutes.</param>
        /// <returns>The configured <see cref="BackgroundBuilder"/>.</returns>
        public static BackgroundBuilder AddMemoryCacheEventRepository(this BackgroundBuilder builder, TimeSpan?expiration = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.AddSingleton <IBackgroundCommandEventRepository>(
                sp => new MemoryCacheBackgroundCommandEventRepository(
                    sp.GetRequiredService <IMemoryCache>(),
                    expiration.HasValue ? expiration.Value : TimeSpan.FromMinutes(10)));
            return(builder);
        }
        /// <summary>
        /// Adds <see cref="DistributedCacheBackgroundCommandEventRepository"/> to store events using <see cref="IDistributedCache"/>.
        /// Do not forget to register a <see cref="IDistributedCache"/> implementation.
        /// </summary>
        /// <param name="builder">The <see cref="BackgroundBuilder"/>.</param>
        /// <param name="expiration">The expiration time of events. Defaults to 10 minutes.</param>
        /// <returns>The configured <see cref="BackgroundBuilder"/>.</returns>
        public static BackgroundBuilder AddDistributedCacheEventRepository(this BackgroundBuilder builder, TimeSpan?expiration = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.TryAddSingleton <IBackgroundCommandSerializer, JsonNetBackgroundCommandSerializer>();

            builder.Services.AddSingleton <IBackgroundCommandEventRepository>(
                sp => new DistributedCacheBackgroundCommandEventRepository(
                    sp.GetRequiredService <IDistributedCache>(),
                    expiration.HasValue ? expiration.Value : TimeSpan.FromMinutes(10),
                    sp.GetService <IBackgroundCommandSerializer>()));
            return(builder);
        }
Exemple #3
0
        /// <summary>
        /// Adds Application Insights monitoring to background processing.
        /// </summary>
        /// <param name="builder">The <see cref="BackgroundBuilder"/>.</param>
        /// <param name="configureOptions">Configure the <see cref="TelemetryClientDecoratorOptions"/> if needed.</param>
        /// <returns>The configured <see cref="BackgroundBuilder"/>.</returns>
        public static BackgroundBuilder AddApplicationInsightsDecorators(
            this BackgroundBuilder builder,
            Action <TelemetryClientDecoratorOptions> configureOptions = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (configureOptions != null)
            {
                builder.Services.Configure(configureOptions);
            }

            builder.TryDecorateDispatcher <TelemetryClientDispatcherDecorator>();
            builder.TryDecorateProcessor <TelemetryClientProcessorDecorator>();
            return(builder);
        }
        /// <summary>
        /// Adds <see cref="CloudTableBackgroundCommandEventRepository"/> to store events using <see cref="CloudTable"/>.
        /// </summary>
        /// <param name="builder">The <see cref="BackgroundBuilder"/>.</param>
        /// <param name="cloudTableProvider">The <see cref="CloudTable"/> provider.</param>
        /// <returns>The configured <see cref="BackgroundBuilder"/>.</returns>
        public static BackgroundBuilder AddCloudTableEventRepository(
            this BackgroundBuilder builder,
            Func <IServiceProvider, CloudTable> cloudTableProvider)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (cloudTableProvider is null)
            {
                throw new ArgumentNullException(nameof(cloudTableProvider));
            }

            builder.Services.TryAddSingleton <IBackgroundCommandSerializer, JsonNetBackgroundCommandSerializer>();
            builder.Services.AddSingleton <IBackgroundCommandEventRepository>(
                sp => new CloudTableBackgroundCommandEventRepository(
                    cloudTableProvider(sp),
                    sp.GetRequiredService <IBackgroundCommandSerializer>()));
            return(builder);
        }
Exemple #5
0
        /// <summary>
        /// Adds dispatcher and processor decorators that sends events to a <see cref="IBackgroundCommandEventRepository"/>.
        /// Do NOT forget to also register a <see cref="IBackgroundCommandEventRepository"/> service for this to work properly.
        /// </summary>
        /// <param name="builder">The <see cref="BackgroundBuilder"/>.</param>
        /// <returns>The configured <see cref="BackgroundBuilder"/>.</returns>
        public static BackgroundBuilder AddBackgroundCommandEventsRepositoryDecorators(this BackgroundBuilder builder)
        {
            if (builder is null)
            {
                throw new System.ArgumentNullException(nameof(builder));
            }

            builder.TryDecorateDispatcher <BackgroundCommandEventRepositoryDispatcherDecorator>();
            builder.TryDecorateProcessor <BackgroundCommandEventRepositoryProcessorDecorator>();
            return(builder);
        }