Files
git.stella-ops.org/src/__Libraries/StellaOps.Provcache/ProvcacheServiceCollectionExtensions.Invalidation.cs

48 lines
1.8 KiB
C#

// SPDX-License-Identifier: BUSL-1.1
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using StellaOps.Messaging;
using StellaOps.Messaging.Abstractions;
using StellaOps.Provcache.Events;
using StellaOps.Provcache.Invalidation;
namespace StellaOps.Provcache;
public static partial class ProvcacheServiceCollectionExtensions
{
/// <summary>
/// Adds event-driven invalidator services for Provcache.
/// </summary>
/// <param name="services">The service collection.</param>
/// <returns>The service collection for chaining.</returns>
public static IServiceCollection AddProvcacheInvalidators(this IServiceCollection services)
{
ArgumentNullException.ThrowIfNull(services);
services.TryAddSingleton<IEventStream<SignerRevokedEvent>>(sp =>
{
var factory = sp.GetRequiredService<IEventStreamFactory>();
return factory.Create<SignerRevokedEvent>(new EventStreamOptions
{
StreamName = SignerRevokedEvent.StreamName
});
});
services.TryAddSingleton<IEventStream<FeedEpochAdvancedEvent>>(sp =>
{
var factory = sp.GetRequiredService<IEventStreamFactory>();
return factory.Create<FeedEpochAdvancedEvent>(new EventStreamOptions
{
StreamName = FeedEpochAdvancedEvent.StreamName
});
});
services.TryAddEnumerable(ServiceDescriptor.Singleton<IProvcacheInvalidator, SignerSetInvalidator>());
services.TryAddEnumerable(ServiceDescriptor.Singleton<IProvcacheInvalidator, FeedEpochInvalidator>());
services.TryAddEnumerable(ServiceDescriptor.Singleton<IHostedService, InvalidatorHostedService>());
return services;
}
}