diff --git a/doc/Snapshots.md b/doc/Snapshots.md index 55e9313..6db1375 100644 --- a/doc/Snapshots.md +++ b/doc/Snapshots.md @@ -90,5 +90,5 @@ To enable this feature you need to implement the following: 1. By default when calling `AggregateRepository.FindAggregateAsync()` it automatically retrieve the last snapshot. You can force not loading any snapshot by calling: ```csharp - FindAggregateAsync(aggregateId, useSnapshot: false) + FindAggregateAsync(aggregateId, ignoreSnapshot: true) ``` \ No newline at end of file diff --git a/src/EventSourcing.sln b/src/EventSourcing.sln index fa22f48..4196301 100644 --- a/src/EventSourcing.sln +++ b/src/EventSourcing.sln @@ -13,6 +13,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ProjectSection(SolutionItems) = preProject ..\.travis.yml = ..\.travis.yml Directory.Build.props = Directory.Build.props + ..\README.md = ..\README.md EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JKang.EventSourcing.Persistence.EfCore", "JKang.EventSourcing.Persistence.EfCore\JKang.EventSourcing.Persistence.EfCore.csproj", "{5473865D-3737-4719-893B-9DD6A10E5A35}" @@ -29,7 +30,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JKang.EventSourcing.Persist EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JKang.EventSourcing.Options", "JKang.EventSourcing.Options\JKang.EventSourcing.Options.csproj", "{5230D7B5-EE3C-43B4-BCBB-2FA6487BDA7D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JKang.EventSourcing.Abstractions.Tests", "JKang.EventSourcing.Abstractions.Tests\JKang.EventSourcing.Abstractions.Tests.csproj", "{1D8A6FFC-1D14-4EA0-A42A-959E38D46EC1}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JKang.EventSourcing.Abstractions.Tests", "JKang.EventSourcing.Abstractions.Tests\JKang.EventSourcing.Abstractions.Tests.csproj", "{1D8A6FFC-1D14-4EA0-A42A-959E38D46EC1}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{6374E9CF-DFD8-4A86-BBEC-6F2D2E09B8D6}" + ProjectSection(SolutionItems) = preProject + ..\doc\CosmosDBSetup.md = ..\doc\CosmosDBSetup.md + ..\doc\DynamoDBSetup.md = ..\doc\DynamoDBSetup.md + ..\doc\EfCoreSetup.md = ..\doc\EfCoreSetup.md + ..\doc\FileSystemSetup.md = ..\doc\FileSystemSetup.md + ..\doc\Snapshots.md = ..\doc\Snapshots.md + ..\doc\StoreInitialization.md = ..\doc\StoreInitialization.md + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -85,6 +96,9 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {6374E9CF-DFD8-4A86-BBEC-6F2D2E09B8D6} = {3CE8F82A-51A6-46BC-9A78-590642AA5242} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E4CE6D6B-D967-402C-BDBE-0949B55C1F1B} EndGlobalSection diff --git a/src/JKang.EventSourcing.Abstractions/Persistence/AggregateRepository.cs b/src/JKang.EventSourcing.Abstractions/Persistence/AggregateRepository.cs index 8e68b7f..9433bca 100644 --- a/src/JKang.EventSourcing.Abstractions/Persistence/AggregateRepository.cs +++ b/src/JKang.EventSourcing.Abstractions/Persistence/AggregateRepository.cs @@ -1,6 +1,5 @@ using JKang.EventSourcing.Domain; using JKang.EventSourcing.Events; -using JKang.EventSourcing.Snapshotting; using JKang.EventSourcing.Snapshotting.Persistence; using System; using System.Collections.Generic; @@ -59,11 +58,12 @@ protected Task GetAggregateIdsAsync() return _eventStore.GetAggregateIdsAsync(); } - protected async Task FindAggregateAsync(TKey id, bool useSnapshot, + protected async Task FindAggregateAsync(TKey id, + bool ignoreSnapshot = false, CancellationToken cancellationToken = default) { IAggregateSnapshot snapshot = null; - if (useSnapshot) + if (!ignoreSnapshot) { snapshot = await _snapshotStore .FindLastSnapshotAsync(id, cancellationToken) diff --git a/src/JKang.EventSourcing.TestingFixtures/GiftCardRepository.cs b/src/JKang.EventSourcing.TestingFixtures/GiftCardRepository.cs index 41e095a..26367de 100644 --- a/src/JKang.EventSourcing.TestingFixtures/GiftCardRepository.cs +++ b/src/JKang.EventSourcing.TestingFixtures/GiftCardRepository.cs @@ -15,8 +15,7 @@ public GiftCardRepository( public Task SaveGiftCardAsync(GiftCard giftCard) => SaveAggregateAsync(giftCard); - public Task FindGiftCardAsync(Guid id, bool useSnapshot = true) - => FindAggregateAsync(id, useSnapshot); + public Task FindGiftCardAsync(Guid id) => FindAggregateAsync(id); public Task GetGiftCardIdsAsync() => GetAggregateIdsAsync(); } diff --git a/src/JKang.EventSourcing.TestingFixtures/IGiftCardRepository.cs b/src/JKang.EventSourcing.TestingFixtures/IGiftCardRepository.cs index 345fcdf..37a0811 100644 --- a/src/JKang.EventSourcing.TestingFixtures/IGiftCardRepository.cs +++ b/src/JKang.EventSourcing.TestingFixtures/IGiftCardRepository.cs @@ -6,7 +6,7 @@ namespace JKang.EventSourcing.TestingFixtures public interface IGiftCardRepository { Task SaveGiftCardAsync(GiftCard giftCard); - Task FindGiftCardAsync(Guid id, bool useSnapshot = true); + Task FindGiftCardAsync(Guid id); Task GetGiftCardIdsAsync(); } } diff --git a/src/JKang.EventSourcing.TestingWebApp/Pages/GiftCards/Details.cshtml.cs b/src/JKang.EventSourcing.TestingWebApp/Pages/GiftCards/Details.cshtml.cs index 227c02a..8fb09c2 100644 --- a/src/JKang.EventSourcing.TestingWebApp/Pages/GiftCards/Details.cshtml.cs +++ b/src/JKang.EventSourcing.TestingWebApp/Pages/GiftCards/Details.cshtml.cs @@ -22,7 +22,7 @@ public DetailsModel(IGiftCardRepository repository) public async Task OnGetAsync(Guid id) { - GiftCard = await _repository.FindGiftCardAsync(id, true) + GiftCard = await _repository.FindGiftCardAsync(id) ?? throw new InvalidOperationException("Gift card not found"); return Page(); @@ -30,7 +30,7 @@ public async Task OnGetAsync(Guid id) public async Task OnPostDebitAsync(Guid id) { - GiftCard = await _repository.FindGiftCardAsync(id, true) + GiftCard = await _repository.FindGiftCardAsync(id) ?? throw new InvalidOperationException("Gift card not found"); GiftCard.Debit(Amount);