Table of Contents

Class GovernanceOutboxDrainHostedService

Namespace
AsiBackbone.AspNetCore.Outbox
Assembly
AsiBackbone.AspNetCore.dll

Runs the provider-neutral outbox drain from an ASP.NET Core or generic-host background worker.

public sealed class GovernanceOutboxDrainHostedService : BackgroundService, IHostedService, IDisposable
Inheritance
GovernanceOutboxDrainHostedService
Implements
Inherited Members

Remarks

Hosting remains outside Core. Startup validates the scoped drain dependency graph and fails when the store or emitter cannot be resolved. Each drain cycle then resolves the drain through a new scoped service provider so durable providers that depend on scoped infrastructure, such as a host-owned EF Core DbContext, remain safe to use. Runtime changes to Enabled pause or resume new drain cycles without terminating the hosted service.

Constructors

GovernanceOutboxDrainHostedService(IServiceScopeFactory, IOptionsMonitor<GovernanceOutboxDrainWorkerOptions>, ILogger<GovernanceOutboxDrainHostedService>, TimeProvider?)

Runs the provider-neutral outbox drain from an ASP.NET Core or generic-host background worker.

public GovernanceOutboxDrainHostedService(IServiceScopeFactory scopeFactory, IOptionsMonitor<GovernanceOutboxDrainWorkerOptions> optionsMonitor, ILogger<GovernanceOutboxDrainHostedService> logger, TimeProvider? timeProvider = null)

Parameters

scopeFactory IServiceScopeFactory

The factory used to create a scope for each drain cycle.

optionsMonitor IOptionsMonitor<GovernanceOutboxDrainWorkerOptions>

The monitored worker options.

logger ILogger<GovernanceOutboxDrainHostedService>

The worker logger.

timeProvider TimeProvider

The clock used for drain timestamps unless RetryClock has been assigned a custom delegate. Defaults to System; dependency injection supplies a registered TimeProvider.

Remarks

Hosting remains outside Core. Startup validates the scoped drain dependency graph and fails when the store or emitter cannot be resolved. Each drain cycle then resolves the drain through a new scoped service provider so durable providers that depend on scoped infrastructure, such as a host-owned EF Core DbContext, remain safe to use. Runtime changes to Enabled pause or resume new drain cycles without terminating the hosted service.

Methods

ExecuteAsync(CancellationToken)

This method is called when the IHostedService starts. The implementation should return a task that represents the lifetime of the long running operation(s) being performed.

protected override Task ExecuteAsync(CancellationToken stoppingToken)

Parameters

stoppingToken CancellationToken

Triggered when StopAsync(CancellationToken) is called.

Returns

Task

A Task that represents the long running operations.

Remarks

See Worker Services in .NET for implementation guidelines.

StartAsync(CancellationToken)

Triggered when the application host is ready to start the service.

public override Task StartAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Indicates that the start process has been aborted.

Returns

Task

A Task that represents the asynchronous Start operation.

StopAsync(CancellationToken)

Triggered when the application host is performing a graceful shutdown.

public override Task StopAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Indicates that the shutdown process should no longer be graceful.

Returns

Task

A Task that represents the asynchronous Stop operation.