Skip to content

Commit

Permalink
Use saga data type to save and update sagas (#486)
Browse files Browse the repository at this point in the history
* Switch persister to use explicit type
  • Loading branch information
danielmarbach authored Mar 31, 2023
1 parent cff50ca commit 8fde441
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PackageReference Include="NServiceBus.AcceptanceTests.Sources" Version="8.0.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="MongoDB.Driver" Version="2.19.1" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PackageReference Include="NServiceBus.AcceptanceTests.Sources" Version="8.0.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="MongoDB.Driver" Version="2.19.1" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PackageReference Include="NServiceBus.PersistenceTests.Sources" Version="8.0.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="MongoDB.Driver" Version="2.19.1" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@

<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" Version="2.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<!-- DO NOT REMOVE MongoDB.Driver, it is added so that dependabot knows about version changes-->
<PackageReference Include="MongoDB.Driver" Version="2.17.1" />
<PackageReference Include="NServiceBus" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="MongoDB.Driver" Version="2.19.1" />
<PackageReference Include="NServiceBus" Version="8.0.3" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="Particular.Approvals" Version="0.3.0" />
<PackageReference Include="PublicApiGenerator" Version="10.3.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="Particular.Approvals" Version="0.4.1" />
<PackageReference Include="PublicApiGenerator" Version="11.0.0" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PackageReference Include="NServiceBus.TransactionalSession" Version="2.0.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="MongoDB.Driver" Version="2.19.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="[2.17.1, 3.0.0)" />
<PackageReference Include="NServiceBus" Version="[8.0.0, 9)" />
<PackageReference Include="Particular.Packaging" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="NServiceBus" Version="[8.0.0, 9.0.0)" />
<PackageReference Include="Particular.Packaging" Version="2.3.0" PrivateAssets="All" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/NServiceBus.Storage.MongoDB/Sagas/SagaPersister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task Save(IContainSagaData sagaData, SagaCorrelationProperty correl
var storageSession = ((SynchronizedStorageSession)session).Session;
var sagaDataType = sagaData.GetType();

var document = sagaData.ToBsonDocument();
var document = sagaData.ToBsonDocument(sagaDataType);
document.Add(versionElementName, 0);

await storageSession.InsertOneAsync(sagaDataType, document, cancellationToken).ConfigureAwait(false);
Expand All @@ -34,7 +34,7 @@ public async Task Update(IContainSagaData sagaData, ISynchronizedStorageSession
var sagaDataType = sagaData.GetType();

var version = storageSession.RetrieveVersion(sagaDataType);
var document = sagaData.ToBsonDocument().SetElement(new BsonElement(versionElementName, version + 1));
var document = sagaData.ToBsonDocument(sagaDataType).SetElement(new BsonElement(versionElementName, version + 1));

var result = await storageSession.ReplaceOneAsync(sagaDataType, filterBuilder.Eq(idElementName, sagaData.Id) & filterBuilder.Eq(versionElementName, version), document, cancellationToken).ConfigureAwait(false);

Expand Down

0 comments on commit 8fde441

Please sign in to comment.