Skip to content

Commit

Permalink
Merge branch 'release/11.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
AGiorgetti committed Dec 9, 2024
2 parents bc3b6cd + c76c1fd commit c0ab21c
Show file tree
Hide file tree
Showing 32 changed files with 929 additions and 450 deletions.
37 changes: 37 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
# NEventStore.Persistence.MongoDB

## 11.0.0

- Support: net6.0, netstandard2.1, net472
- Updated MongoDb driver to 3.0.0
- Updated nuget package icon.

### Breaking Changes

- Carefully read the [MongoDB C# Driver 3.0 Migration Guide](https://www.mongodb.com/docs/drivers/csharp/v3.0/upgrade/v3/)
- dropped netstandard2.0 support.
- dropped net461 support.
- Removed Obsolete Extension methods: `ExtensionMethods.ToMongoCommit_original()`, `ExtensionMethods.ToCommit_original()`, `ExtensionMethods.AsDictionary<Tkey, Tvalue>()`, `ExtensionMethods.ToMongoCommitIdQuery()`
- Check your GUID serialization:
- if it's a new project, you should not have any problem; you'll use the new GUID serialization format.
- if it's an old project, you should check the GUID serialization format:
- if you are using the `Standard` format, you should not have any problem.
- if you are (most likely) using the `CSharpLegacy` format, you should change the GUID serialization format to `CSharpLegacy`:
```csharp
BsonSerializer.RegisterSerializer(new GuidSerializer(GuidRepresentation.CSharpLegacy));
```
or:
```csharp
BsonClassMap.RegisterClassMap<MongoCommit>(cm =>
{
cm.AutoMap();
cm.GetMemberMap(c => c.CommitId).SetSerializer(new GuidSerializer(GuidRepresentation.CSharpLegacy));
});
```
- To serialize GUIDs in Lists or Dictionary of objects, you should also remember to properly set the Guid representation for the object serializer, with something like:
```csharp
BsonSerializer.RegisterSerializer(new ObjectSerializer(
BsonSerializer.LookupDiscriminatorConvention(typeof(object)), GuidRepresentation.CSharpLegacy, ObjectSerializer.AllAllowedTypes));

```
see README.md for more information.
- class `MongoShapshotFields` renamed to: `MongoSnapshotFields`

## 10.0.1

- Limit MongoDb allowed versions from 2.28.0 to anything less than 3.0.0 (which has many breaking changes to take care of).
Expand Down
50 changes: 44 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ Mongo Persistence Engine for NEventStore

NEventStore.Persistence.MongoDB currently supports:

- .net framework 4.6.2
- .net standard 2.0
- .net6.0+
- .net standard 2.1
- .net framework 4.7.2

Build Status
===
Expand Down Expand Up @@ -59,13 +60,50 @@ To run tests in visual studio using NUnit as a Test Runner you need to explicitl
-Trait:"Explicit"
```

## GUID

Pay attention to GUID serialization and deserialization, MongoDB driver uses a specific representation for GUIDs.

Up to MongoDb 2.30.0 the driver uses the `CSharpLegacy` representation for GUIDs (drivers for other languages use a different byte ordering).

From 3.0.0 the driver default to the `Standard` representation (which has the same byte ordering in all the different drivers).

The `CommitId` of each `CommitAttempt` is actually a GUID, to guarantee compatibility for old projects you should to use the `CSharpLegacy` representation,
you can do this either by:

- Configuring a GUID Serializer globally for the MongoDB driver:
```csharp
BsonSerializer.RegisterSerializer(new GuidSerializer(GuidRepresentation.CSharpLegacy));
```

- Customizing the serialization for the `CommitId` property of the `MongoCommit` class (see below):
```csharp
BsonClassMap.RegisterClassMap<MongoCommit>(cm =>
{
cm.AutoMap();
cm.GetMemberMap(c => c.CommitId).SetSerializer(new GuidSerializer(GuidRepresentation.CSharpLegacy));
});
```

To serialize GUIDs in Lists or Dictionary of objects, you should also remember to properly set the Guid representation for the object serializer, with something like:
```csharp
BsonSerializer.RegisterSerializer(new ObjectSerializer(
BsonSerializer.LookupDiscriminatorConvention(typeof(object)), GuidRepresentation.CSharpLegacy, ObjectSerializer.AllAllowedTypes));

```

Reference:
- [GUIDs](https://www.mongodb.com/docs/drivers/csharp/current/fundamentals/serialization/guid-serialization/)
- [Guid Representation in Dictionary](https://jira.mongodb.org/browse/CSHARP-4987?jql=text%20~%20%22GuidRepresentation%20dictionary%22)


## Configure / Customize Commit Serialization

You can configure the serialization process using the standard methods offered by the MongoDB C# driver.

You'll need to specify the class mapping or implement an IBsonSerializationProvider for the ```MongoCommit``` class and registerm them before you start using any database operation.
You'll need to specify the class mapping or implement an `IBsonSerializationProvider` for the `MongoCommit` class and register it before you start using any database operation.

For detailed information on how to configure the serialization in MongoDB head to the official [Serialization documentation](http://mongodb.github.io/mongo-csharp-driver/2.2/reference/bson/serialization/)
For detailed information on how to configure the serialization in MongoDB head to the official [Serialization](https://www.mongodb.com/docs/drivers/csharp/current/fundamentals/serialization/) page.

### BsonClassMap

Expand Down Expand Up @@ -119,7 +157,7 @@ class MongoCommitSerializer : SerializerBase<MongoCommit>
}
```

you can then register the serialization provider using: [```BsonSerializer.RegisterSerializationProvider```](http://api.mongodb.com/csharp/2.2/html/M_MongoDB_Bson_Serialization_BsonSerializer_RegisterSerializationProvider.htm)
You can then register the serialization provider using: [```BsonSerializer.RegisterSerializationProvider```](http://api.mongodb.com/csharp/2.2/html/M_MongoDB_Bson_Serialization_BsonSerializer_RegisterSerializationProvider.htm)

## How to contribute

Expand All @@ -143,7 +181,7 @@ Build machine uses [GitVersion](https://github.com/GitTools/GitVersion) to manag

A commit on master can be done only following the [Git-Flow](http://nvie.com/posts/a-successful-git-branching-model/) model, as a result of a new release coming from develop, or with an hotfix.

### Quick Info for NEventstore projects
### Quick Info for NEventStore projects

Just clone the repository and from command line checkout develop branch with

Expand Down
2 changes: 1 addition & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ Write-Host "NuGet Packages creation"
#dotnet pack ./src/NEventStore.Persistence.MongoDB/NEventStore.Persistence.MongoDB.Core.csproj --no-build -c $configuration -o $artifacts -p:NuspecFile="" -p:NuspecProperties="pippo=$configuration;version=$nugetversion"

#Write-Host nuget pack ./src/.nuget/NEventStore.Persistence.MongoDB.nuspec -properties "version=$nugetversion;configuration=$configuration"
nuget pack ./src/.nuget/NEventStore.Persistence.MongoDB.nuspec -properties "version=$nugetversion;configuration=$configuration" -OutputDirectory $artifacts -Symbols
nuget pack ./src/.nuget/NEventStore.Persistence.MongoDB.nuspec -properties "version=$nugetversion;configuration=$configuration" -OutputDirectory $artifacts -Symbols -SymbolPackageFormat snupkg
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,13 @@ indent_size = 4
indent_style = space

[*.cs]
csharp_new_line_before_open_brace = all
csharp_new_line_before_open_brace = all

# RCS1229: Use async/await when necessary.
dotnet_diagnostic.RCS1229.severity = error

# IDE0290: Use primary constructor
csharp_style_prefer_primary_constructors = false

# IDE0028: Simplify collection initialization
dotnet_style_collection_initializer = false
32 changes: 19 additions & 13 deletions src/.nuget/NEventStore.Persistence.MongoDB.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,41 @@
<tags>events, event sourcing, cqrs, storage, persistence, database, mongodb</tags>
<license type="file">LICENSE.md</license>
<readme>README.md</readme>
<icon>icon.png</icon>
<repository type="git" url="https://github.com/NEventStore/NEventStore.Persistence.MongoDB.git" />
<copyright>Copyright (c) 2014 NEventStore</copyright>
<!--
Until this is on develop branch, this version should be the previous version, so it made it compatible
with pre-release of the actual version. Ex, if we are on 6.0.0 unstable, dependency from NEventStore should
be latest stable version so it can take prerelease of 6.0.0 version.
With (5.4 we are telling NuGet that we need a version greater than 5.4 so we are allowing all the prerelease
6.x.x versions
-->
with pre-release of the actual version. Ex, if we are on 6.0.0 unstable, dependency from NEventStore should
be latest stable version so it can take prerelease of 6.0.0 version.
With (5.4 we are telling NuGet that we need a version greater than 5.4 so we are allowing all the prerelease
6.x.x versions
-->
<dependencies>
<group targetFramework=".NETFramework4.6.2">
<group targetFramework=".NETFramework4.7.2">
<dependency id="NEventStore" version="[9.1.1,10.0.0)" exclude="Build,Analyzers"/>
<dependency id="Microsoft.Extensions.Logging.Abstractions" version="7.0.1" exclude="Build,Analyzers"/>
<dependency id="MongoDB.Driver" version="[2.28.0,3.0.0)" exclude="Build,Analyzers"/>
<dependency id="MongoDB.Driver" version="[3.0.0,4.0.0)" exclude="Build,Analyzers"/>
</group>
<group targetFramework=".NETStandard2.0">
<group targetFramework=".NETStandard2.1">
<dependency id="NEventStore" version="[9.1.1,10.0.0)" exclude="Build,Analyzers"/>
<dependency id="Microsoft.Extensions.Logging.Abstractions" version="7.0.1" exclude="Build,Analyzers"/>
<dependency id="MongoDB.Driver" version="[2.28.0,3.0.0)" exclude="Build,Analyzers"/>
<dependency id="MongoDB.Driver" version="[3.0.0,4.0.0)" exclude="Build,Analyzers"/>
</group>
<group targetFramework=".net6.0">
<dependency id="NEventStore" version="[9.1.1,10.0.0)" exclude="Build,Analyzers"/>
<dependency id="MongoDB.Driver" version="[3.0.0,4.0.0)" exclude="Build,Analyzers"/>
</group>
</dependencies>
<frameworkAssemblies>
<frameworkAssembly assemblyName="System.Configuration" targetFramework=".NETFramework4.6.2" />
<frameworkAssembly assemblyName="System.Transactions" targetFramework=".NETFramework4.6.2" />
<frameworkAssembly assemblyName="System.Configuration" targetFramework=".NETFramework4.7.2" />
</frameworkAssemblies>
</metadata>
<files>
<!--<file src="bin\$configuration$\**" target="lib"/>-->
<file src="..\NEventStore.Persistence.MongoDB\bin\$configuration$\**\NEventStore.Persistence.MongoDB.dll" target="lib"/>
<file src="..\NEventStore.Persistence.MongoDB\bin\$configuration$\**\NEventStore.Persistence.MongoDB.xml" target="lib"/>
<file src="..\NEventStore.Persistence.MongoDB\bin\$configuration$\**\NEventStore.Persistence.MongoDB.pdb" target="lib"/>
<file src="..\..\README.md" target="" />
<file src="..\..\LICENSE.md" target="" />
<file src="..\..\icon.png" target="" />
</files>
</package>
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;net462</TargetFrameworks>
<TargetFrameworks>net8.0;net472</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<ApplicationIcon />
<OutputTypeEx>exe</OutputTypeEx>
<StartupObject />
<OutputType>Exe</OutputType>
<DebugType>pdbonly</DebugType>
<DebugSymbols>true</DebugSymbols>
<LangVersion>12.0</LangVersion>
</PropertyGroup>

<PropertyGroup>
<DefineConstants Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">TRACE;DEBUG</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.6" />
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal static IStoreEvents WireupEventStore()
// .LogToConsoleWindow(LogLevel.Verbose)
.UsingMongoPersistence(GetConnectionString(), new DocumentObjectSerializer())
.InitializeStorageEngine()
#if NET462
#if NET472_OR_GREATER
.TrackPerformanceInstance("example")
#endif
// .HookIntoPipelineUsing(new[] { new AuthorizationPipelineHook() })
Expand Down
1 change: 1 addition & 0 deletions src/NEventStore.Persistence.MongoDB.Core.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
..\build.ps1 = ..\build.ps1
..\Changelog.md = ..\Changelog.md
..\GitVersion.yml = ..\GitVersion.yml
..\icon.png = ..\icon.png
..\README.md = ..\README.md
EndProjectSection
EndProject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using global::MongoDB.Bson.Serialization.Serializers;
using global::MongoDB.Bson.Serialization;
using NEventStore.Serialization;
using global::MongoDB.Bson;
#if MSTEST
using global::MongoDB.Driver;
#endif
Expand All @@ -12,12 +13,17 @@ public class AcceptanceTestMongoPersistenceFactory : MongoPersistenceFactory {

static AcceptanceTestMongoPersistenceFactory() {
// MongoDb serialization changed
// MongoDb 3.0.0 GUID serialization changed
BsonSerializer.RegisterSerializer(new GuidSerializer(GuidRepresentation.CSharpLegacy));
// when serializing guid in a Dictionary<object, object> take a look at the comment here:
// https://jira.mongodb.org/browse/CSHARP-4987?jql=text%20~%20%22GuidRepresentation%20dictionary%22
// it seems you also need to configure the ObjectSerializer
// What Object Types Can Be Serialized?
// https://www.mongodb.com/docs/drivers/csharp/current/faq/#what-object-types-can-be-serialized-
BsonSerializer.RegisterSerializer(new ObjectSerializer(ObjectSerializer.AllAllowedTypes));
BsonSerializer.RegisterSerializer(new ObjectSerializer(
BsonSerializer.LookupDiscriminatorConvention(typeof(object)), GuidRepresentation.CSharpLegacy, ObjectSerializer.AllAllowedTypes));
}

public AcceptanceTestMongoPersistenceFactory(MongoPersistenceOptions options = null)
public AcceptanceTestMongoPersistenceFactory(MongoPersistenceOptions? options = null)
: base(
GetConnectionString,
new DocumentObjectSerializer(),
Expand All @@ -30,7 +36,7 @@ private static MongoPersistenceOptions ConfigureOptionsForTesting(MongoPersisten
}

internal static string GetConnectionString() {
string connectionString = Environment.GetEnvironmentVariable(EnvVarConnectionStringKey, EnvironmentVariableTarget.Process);
var connectionString = Environment.GetEnvironmentVariable(EnvVarConnectionStringKey, EnvironmentVariableTarget.Process);

if (connectionString == null) {
string message = string.Format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ namespace NEventStore.Persistence.MongoDB.Tests.AcceptanceTests
#endif
public class Verify_safe_generator_not_create_hole : PersistenceEngineConcern
{
private string _streamId;
private string _bucketId;
private CommitAttempt _attempt;
private string? _streamId;
private string? _bucketId;
private CommitAttempt? _attempt;

public Verify_safe_generator_not_create_hole()
{
Expand Down Expand Up @@ -85,9 +85,9 @@ public void Holes_are_presents()
#endif
public class Holes_are_filled_after_concurrency_exception : PersistenceEngineConcern
{
private string _streamId;
private string _bucketId;
private CommitAttempt _attempt;
private string? _streamId;
private string? _bucketId;
private CommitAttempt? _attempt;

public Holes_are_filled_after_concurrency_exception()
{
Expand Down Expand Up @@ -145,9 +145,9 @@ public void Holes_are_not_presents()
#endif
public class Holes_are_not_filled_as_default_behavior : PersistenceEngineConcern
{
private string _streamId;
private string _bucketId;
private CommitAttempt _attempt;
private string? _streamId;
private string? _bucketId;
private CommitAttempt? _attempt;

public Holes_are_not_filled_as_default_behavior()
{
Expand Down Expand Up @@ -209,9 +209,9 @@ public void Holes_are_presents()
#endif
public class Default_behavior_after_concurrency_exception : PersistenceEngineConcern
{
private string _streamId;
private string _bucketId;
private CommitAttempt _attempt;
private string? _streamId;
private string? _bucketId;
private CommitAttempt? _attempt;

protected override void Context()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public void No_stream_heads_are_saved()
#if MSTEST
[TestClass]
#endif
public class Issue40_calling_AddShapshot_function_when_snapshot_disabled_throws : PersistenceEngineConcern
public class Issue40_calling_AddSnapshot_function_when_snapshot_disabled_throws : PersistenceEngineConcern
{
public Issue40_calling_AddShapshot_function_when_snapshot_disabled_throws()
public Issue40_calling_AddSnapshot_function_when_snapshot_disabled_throws()
{
var options = new MongoPersistenceOptions
{
Expand All @@ -95,7 +95,7 @@ protected override void Context()
{
}

private Exception _ex;
private Exception? _ex;

protected override void Because()
{
Expand Down Expand Up @@ -140,7 +140,7 @@ protected override void Context()
{
}

private Exception _ex;
private Exception? _ex;

protected override void Because()
{
Expand Down Expand Up @@ -185,7 +185,7 @@ protected override void Context()
{
}

private Exception _ex;
private Exception? _ex;

protected override void Because()
{
Expand Down
Loading

0 comments on commit c0ab21c

Please sign in to comment.