Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PublishKbHostedService"/> class.
 /// </summary>
 /// <param name="settings">background services settings.</param>
 /// <param name="qnAService">QnA service.</param>
 /// <param name="logger">Logger.</param>
 /// <param name="telemetryClient">Telemetry client.</param>
 public PublishKbHostedService(
     BackgroundServicesSettings settings,
     IQnAService qnAService,
     ILogger <PublishKbHostedService> logger,
     TelemetryClient telemetryClient)
 {
     this.settings        = settings ?? throw new ArgumentNullException(nameof(settings));
     this.qnAService      = qnAService ?? throw new ArgumentNullException(nameof(qnAService));
     this.logger          = logger ?? throw new ArgumentNullException(nameof(logger));
     this.telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DeleteUserDataHostedService"/> class.
 /// </summary>
 /// <param name="settings">background services settings.</param>
 /// <param name="scopeFactory">Service scope factory.</param>
 /// <param name="logger">Logger.</param>
 /// <param name="telemetryClient">Telemetry client.</param>
 public DeleteUserDataHostedService(
     BackgroundServicesSettings settings,
     IServiceScopeFactory scopeFactory,
     ILogger <DeleteUserDataHostedService> logger,
     TelemetryClient telemetryClient)
 {
     this.settings        = settings ?? throw new ArgumentNullException(nameof(settings));
     this.scopeFactory    = scopeFactory ?? throw new ArgumentNullException(nameof(scopeFactory));
     this.logger          = logger ?? throw new ArgumentNullException(nameof(logger));
     this.telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient));
 }
        /// <summary>
        /// Service Collection extension.
        ///
        /// Injects backgorund services.
        /// </summary>
        /// <param name="services">Servie collection.</param>
        /// <param name="configuration">Configuration.</param>
        /// <returns>Service collection.</returns>
        public static IServiceCollection AddBackgroundServices(this IServiceCollection services, IConfiguration configuration)
        {
            var settings = new BackgroundServicesSettings
            {
                PublishKbFrequencyInMinutes   = configuration.GetValue <int>("BackgroundServices:PublishKbFrequencyInMinutes"),
                DeleteUserDataFrequencyInDays = configuration.GetValue <int>("BackgroundServices:DeleteUserDataFrequencyInDays"),
            };

            services.AddSingleton <BackgroundServicesSettings>(settings);
            services.AddHostedService <PublishKbHostedService>();
            services.AddHostedService <DeleteUserDataHostedService>();

            return(services);
        }