Skip to content

Commit

Permalink
fix: snapshot verifier registrations
Browse files Browse the repository at this point in the history
  • Loading branch information
emalfroy authored and ArneD committed Sep 8, 2023
1 parent a5e8ea8 commit 312295f
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,28 @@
using System;
using System.Collections.Generic;
using AggregateSource;
using EventHandling;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using SqlStreamStore;

public static class SnapshotVerifierExtensions
{
public static IServiceCollection AddSnapshotVerificationServices<TAggregateRoot, TStreamId>(
public static IServiceCollection AddSnapshotVerificationServices(
this IServiceCollection services,
string snapshotConnectionString,
string snapshotSchema,
string snapshotVerificationStatesTableName = "SnapshotVerificationStates")
where TAggregateRoot : class, IAggregateRootEntity, ISnapshotable
where TStreamId : class
{
services.AddSingleton(new MsSqlSnapshotStoreQueries(snapshotConnectionString, snapshotSchema));
services.AddScoped<ISnapshotVerificationRepository>(_ => new SnapshotVerificationRepository(snapshotConnectionString, snapshotSchema, snapshotVerificationStatesTableName));
services.AddScoped<IAggregateSnapshotRepository<TAggregateRoot>, AggregateSnapshotRepository<TAggregateRoot>>();
services.AddScoped<IAggregateEventsRepository<TAggregateRoot, TStreamId>, AggregateEventsRepository<TAggregateRoot, TStreamId>>();
return services;
}

public static IServiceCollection AddHostedSnapshotVerifierService<TAggregateRoot, TStreamId>(
this IServiceCollection services,
Func<TAggregateRoot> aggregateFactory,
Func<TAggregateRoot, TStreamId> aggregateIdFactory,
List<string> membersToIgnoreInVerification)
where TAggregateRoot : class, IAggregateRootEntity, ISnapshotable
Expand All @@ -36,8 +35,17 @@ public static IServiceCollection AddHostedSnapshotVerifierService<TAggregateRoot
aggregateIdFactory,
membersToIgnoreInVerification,
x.GetRequiredService<ISnapshotVerificationRepository>(),
x.GetRequiredService<IAggregateSnapshotRepository<TAggregateRoot>>(),
x.GetRequiredService<IAggregateEventsRepository<TAggregateRoot, TStreamId>>(),
new AggregateSnapshotRepository<TAggregateRoot>(
x.GetRequiredService<MsSqlSnapshotStoreQueries>(),
x.GetRequiredService<EventDeserializer>(),
x.GetRequiredService<EventMapping>(),
aggregateFactory,
x.GetRequiredService<ILoggerFactory>()),
new AggregateEventsRepository<TAggregateRoot, TStreamId>(
x.GetRequiredService<EventDeserializer>(),
x.GetRequiredService<EventMapping>(),
x.GetRequiredService<IReadonlyStreamStore>(),
aggregateFactory),
x.GetService<ISnapshotVerificationNotifier>(), x.GetRequiredService<ILoggerFactory>()));

return services;
Expand Down

0 comments on commit 312295f

Please sign in to comment.