using BuildingBlocks.Domain.Model; using BuildingBlocks.Exception; namespace BuildingBlocks.EventStoreDB.Repository; public static class RepositoryExtensions { public static async Task Get( this IEventStoreDBRepository repository, long id, CancellationToken cancellationToken ) where T : class, IAggregate { var entity = await repository.Find(id, cancellationToken); return entity ?? throw AggregateNotFoundException.For(id); } public static async Task GetAndUpdate( this IEventStoreDBRepository repository, long id, Action action, long? expectedVersion = null, CancellationToken cancellationToken = default ) where T : class, IAggregate { var entity = await repository.Get(id, cancellationToken); action(entity); return await repository.Update(entity, expectedVersion, cancellationToken); } }