Class GlobalStreamProjectionHost<TState>
- Namespace
- Excalibur.EventSourcing.Projections
- Assembly
- Excalibur.EventSourcing.dll
Background service that hosts a IGlobalStreamProjection<TState>, continuously reading from the global event stream via IGlobalStreamQuery and applying events to the projection state.
public sealed class GlobalStreamProjectionHost<TState> : BackgroundService, IHostedService, IDisposable where TState : class, new()
Type Parameters
TStateThe projection state type.
- Inheritance
-
GlobalStreamProjectionHost<TState>
- Implements
- Inherited Members
Remarks
This host manages the lifecycle of a global stream projection, including:
- Reading events from the global stream in configurable batches
- Applying events to the projection via ApplyAsync(IDomainEvent, TState, CancellationToken)
- Tracking processing position for checkpoint/resume
- Graceful shutdown with cancellation support
Events from the event store are StoredEvent records and must be deserialized to IDomainEvent before applying to the projection. This host uses IEventSerializer for deserialization.
Constructors
GlobalStreamProjectionHost(IServiceScopeFactory, IEventSerializer, IOptions<GlobalStreamProjectionOptions>, ILogger<GlobalStreamProjectionHost<TState>>, IServiceProvider)
Initializes a new instance of the GlobalStreamProjectionHost<TState> class.
public GlobalStreamProjectionHost(IServiceScopeFactory scopeFactory, IEventSerializer eventSerializer, IOptions<GlobalStreamProjectionOptions> options, ILogger<GlobalStreamProjectionHost<TState>> logger, IServiceProvider serviceProvider)
Parameters
scopeFactoryIServiceScopeFactoryThe scope factory used to resolve the (typically scoped) global-stream query, projection, checkpoint store, and optional cursor-map store from a fresh scope per polling cycle (avoids a captive dependency in this singleton host).
eventSerializerIEventSerializerThe event serializer for deserializing stored events.
optionsIOptions<GlobalStreamProjectionOptions>The projection host options.
loggerILogger<GlobalStreamProjectionHost<TState>>The logger.
serviceProviderIServiceProviderThe service provider for resolving internal observability services.
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
stoppingTokenCancellationTokenTriggered when StopAsync(CancellationToken) is called.
Returns
Remarks
See Worker Services in .NET for implementation guidelines.