Compare commits

..

5 Commits

Author SHA1 Message Date
Alexandre SPIESER 9c48653dc6 Merge pull request #57 from mrtaikandi/mongodriver-2.25
Upgrade MongoDb driver and its related packages to 2.25.0
2024-05-28 15:16:53 +01:00
Mohammadreza Taikandi b083988509 Upgrade MongoDb driver and its related packages to 2.25.0 2024-05-28 15:07:12 +01:00
Alexandre SPIESER 7bd356c7da Merge pull request #56 from mrtaikandi/mongodriver-2.20
Upgrade to MongoDb Driver 2.20 and use GuidRepresentationMode.V3 as the default representation.
This potentially can cause a breaking change to the package consumer, but the behaviour can be set to V2 by overriding the void SetGuidRepresentation(GuidRepresentation guidRepresentation) method.
GuidRepresentation and GuidRepresentationMode will be removed in the next major release of the MongoDB Driver:
https://www.mongodb.com/community/forums/t/c-guid-style-dont-work/126901/2
What's new in 2.20 and 2.19:
https://www.mongodb.com/docs/drivers/csharp/current/whats-new/#std-label-csharp-whats-new
2023-08-11 11:07:13 +01:00
Mohammadreza Taikandi f59cccb3d9 Upgrade to MongoDb Driver 2.20 and use GuidRepresentationMode.V3 as default representation. 2023-08-07 11:34:35 +01:00
Alexandre Spieser 710b7b992f upgrade to MongoDb Driver 2.18 - 2.19 seems to have some broken some tests, investigating. 2023-08-02 22:56:58 +01:00
18 changed files with 230 additions and 68 deletions
@@ -7,7 +7,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.1.2" /> <PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.1.2" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="2.1.2" /> <PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="2.1.2" />
<PackageReference Include="MongoDB.Driver" Version="2.15.0" /> <PackageReference Include="MongoDB.Driver" Version="2.25.0" />
<PackageReference Include="xunit" Version="2.5.0" /> <PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.console" Version="2.5.0"> <PackageReference Include="xunit.runner.console" Version="2.5.0">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
@@ -30,4 +30,4 @@
<ProjectReference Include="..\MongoDbGenericRepository\MongoDbGenericRepository.csproj" /> <ProjectReference Include="..\MongoDbGenericRepository\MongoDbGenericRepository.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>
@@ -531,8 +531,8 @@ public class UpdateManyAsyncTests : GenericTestContext<MongoDbUpdater>
private Mock<IMongoCollection<TestDocument>> SetupCollection(long count, string partitionKey = null) private Mock<IMongoCollection<TestDocument>> SetupCollection(long count, string partitionKey = null)
{ {
var replacedId = Fixture.Create<Guid>(); var replacedId = Fixture.Create<Guid>();
var replaceResult = new ReplaceOneResult.Acknowledged(count, count, BsonValue.Create(replacedId)); var replaceResult = new ReplaceOneResult.Acknowledged(count, count, new BsonBinaryData(replacedId, GuidRepresentation.Standard));
var updateResult = new UpdateResult.Acknowledged(count, count, BsonValue.Create(replacedId)); var updateResult = new UpdateResult.Acknowledged(count, count, new BsonBinaryData(replacedId, GuidRepresentation.Standard));
var collection = MockOf<IMongoCollection<TestDocument>>(); var collection = MockOf<IMongoCollection<TestDocument>>();
collection collection
@@ -530,8 +530,8 @@ public class UpdateManyTests : GenericTestContext<MongoDbUpdater>
private Mock<IMongoCollection<TestDocument>> SetupCollection(long count, string partitionKey = null) private Mock<IMongoCollection<TestDocument>> SetupCollection(long count, string partitionKey = null)
{ {
var replacedId = Fixture.Create<Guid>(); var replacedId = Fixture.Create<Guid>();
var replaceResult = new ReplaceOneResult.Acknowledged(count, count, BsonValue.Create(replacedId)); var replaceResult = new ReplaceOneResult.Acknowledged(count, count, new BsonBinaryData(replacedId, GuidRepresentation.Standard));
var updateResult = new UpdateResult.Acknowledged(count, count, BsonValue.Create(replacedId)); var updateResult = new UpdateResult.Acknowledged(count, count, new BsonBinaryData(replacedId, GuidRepresentation.Standard));
var collection = MockOf<IMongoCollection<TestDocument>>(); var collection = MockOf<IMongoCollection<TestDocument>>();
collection collection
@@ -755,8 +755,8 @@ public class UpdateOneAsyncTests : GenericTestContext<MongoDbUpdater>
{ {
var replacedId = Fixture.Create<Guid>(); var replacedId = Fixture.Create<Guid>();
var count = Fixture.Create<long>(); var count = Fixture.Create<long>();
var replaceResult = new ReplaceOneResult.Acknowledged(count, 1, BsonValue.Create(replacedId)); var replaceResult = new ReplaceOneResult.Acknowledged(count, 1, new BsonBinaryData(replacedId, GuidRepresentation.Standard));
var updateResult = new UpdateResult.Acknowledged(count, 1, BsonValue.Create(replacedId)); var updateResult = new UpdateResult.Acknowledged(count, 1, new BsonBinaryData(replacedId, GuidRepresentation.Standard));
var collection = MockOf<IMongoCollection<TestDocument>>(); var collection = MockOf<IMongoCollection<TestDocument>>();
collection collection
@@ -754,8 +754,8 @@ public class UpdateOneTests : GenericTestContext<MongoDbUpdater>
{ {
var replacedId = Fixture.Create<Guid>(); var replacedId = Fixture.Create<Guid>();
var count = Fixture.Create<long>(); var count = Fixture.Create<long>();
var replaceResult = new ReplaceOneResult.Acknowledged(count, 1, BsonValue.Create(replacedId)); var replaceResult = new ReplaceOneResult.Acknowledged(count, 1, new BsonBinaryData(replacedId, GuidRepresentation.Standard));
var updateResult = new UpdateResult.Acknowledged(count, 1, BsonValue.Create(replacedId)); var updateResult = new UpdateResult.Acknowledged(count, 1, new BsonBinaryData(replacedId, GuidRepresentation.Standard));
var collection = MockOf<IMongoCollection<TestDocument>>(); var collection = MockOf<IMongoCollection<TestDocument>>();
collection collection
+45 -1
View File
@@ -11,7 +11,51 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.1.3" newVersion="4.1.1.3" /> <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Win32.Registry" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="MongoDB.Bson" publicKeyToken="null" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.20.0.0" newVersion="2.20.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="MongoDB.Driver.Core" publicKeyToken="null" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.20.0.0" newVersion="2.20.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="MongoDB.Libmongocrypt" publicKeyToken="null" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.9.0.0" newVersion="1.9.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="mscorlib" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Security.AccessControl" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Security.Principal.Windows" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="ZstdSharp" publicKeyToken="8d151af33a4ad5cf" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-0.7.3.0" newVersion="0.7.3.0" />
</dependentAssembly> </dependentAssembly>
</assemblyBinding> </assemblyBinding>
</runtime> </runtime>
@@ -23,20 +23,5 @@ namespace IntegrationTests.Infrastructure
{ {
MongoDbContext.DropCollection<TDocument>(partitionKey); MongoDbContext.DropCollection<TDocument>(partitionKey);
} }
/// <summary>
/// Gets the max of a property in a mongodb collections that is satisfying the filter.
/// </summary>
/// <typeparam name="TDocument">The document type.</typeparam>
/// <typeparam name="TKey">The type of the primary key.</typeparam>
/// <returns></returns>
public async Task<TDocument> GetByMaxAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, object>> orderByDescending)
where TDocument : IDocument<TKey>
where TKey : System.IEquatable<TKey>
{
return await GetCollection<TDocument, TKey>().Find(Builders<TDocument>.Filter.Where(filter))
.SortByDescending(orderByDescending)
.FirstOrDefaultAsync();
}
} }
} }
+76 -23
View File
@@ -34,32 +34,48 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="AWSSDK.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604, processorArchitecture=MSIL">
<HintPath>..\packages\AWSSDK.Core.3.7.100.14\lib\net45\AWSSDK.Core.dll</HintPath>
</Reference>
<Reference Include="AWSSDK.SecurityToken, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604, processorArchitecture=MSIL">
<HintPath>..\packages\AWSSDK.SecurityToken.3.7.100.14\lib\net45\AWSSDK.SecurityToken.dll</HintPath>
</Reference>
<Reference Include="Crc32C.NET, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Crc32C.NET, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Crc32C.NET.1.0.5.0\lib\net20\Crc32C.NET.dll</HintPath> <HintPath>..\packages\Crc32C.NET.1.0.5.0\lib\net20\Crc32C.NET.dll</HintPath>
</Reference> </Reference>
<Reference Include="DnsClient, Version=1.4.0.0, Culture=neutral, PublicKeyToken=4574bb5573c51424, processorArchitecture=MSIL"> <Reference Include="DnsClient, Version=1.6.1.0, Culture=neutral, PublicKeyToken=4574bb5573c51424, processorArchitecture=MSIL">
<HintPath>..\packages\DnsClient.1.4.0\lib\net45\DnsClient.dll</HintPath> <HintPath>..\packages\DnsClient.1.6.1\lib\net471\DnsClient.dll</HintPath>
</Reference> </Reference>
<Reference Include="MongoDB.Bson, Version=2.13.2.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Bson.2.13.2\lib\net452\MongoDB.Bson.dll</HintPath> <HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.5.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference> </Reference>
<Reference Include="MongoDB.Driver, Version=2.13.2.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.2.13.2\lib\net452\MongoDB.Driver.dll</HintPath> <HintPath>..\packages\Microsoft.Extensions.Logging.Abstractions.2.0.0\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
</Reference> </Reference>
<Reference Include="MongoDB.Driver.Core, Version=2.13.2.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Microsoft.Win32.Registry, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.Core.2.13.2\lib\net452\MongoDB.Driver.Core.dll</HintPath> <HintPath>..\packages\Microsoft.Win32.Registry.5.0.0\lib\net461\Microsoft.Win32.Registry.dll</HintPath>
</Reference> </Reference>
<Reference Include="MongoDB.Libmongocrypt, Version=1.2.2.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="MongoDB.Bson, Version=2.20.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Libmongocrypt.1.2.2\lib\net452\MongoDB.Libmongocrypt.dll</HintPath> <HintPath>..\packages\MongoDB.Bson.2.20.0\lib\net472\MongoDB.Bson.dll</HintPath>
</Reference> </Reference>
<Reference Include="MongoDbGenericRepository, Version=1.4.8.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="MongoDB.Driver, Version=2.18.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDbGenericRepository.1.4.8\lib\net452\MongoDbGenericRepository.dll</HintPath> <HintPath>..\packages\MongoDB.Driver.2.18.0\lib\net472\MongoDB.Driver.dll</HintPath>
</Reference> </Reference>
<Reference Include="MongoDB.Driver.Core, Version=2.20.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.Core.2.20.0\lib\net472\MongoDB.Driver.Core.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Libmongocrypt, Version=1.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Libmongocrypt.1.9.0\lib\netstandard2.0\MongoDB.Libmongocrypt.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="nunit.framework, Version=3.13.2.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL"> <Reference Include="nunit.framework, Version=3.13.2.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.13.2\lib\net45\nunit.framework.dll</HintPath> <HintPath>..\packages\NUnit.3.13.2\lib\net45\nunit.framework.dll</HintPath>
</Reference> </Reference>
<Reference Include="SharpCompress, Version=0.23.0.0, Culture=neutral, PublicKeyToken=afb0a02973931d96, processorArchitecture=MSIL"> <Reference Include="SharpCompress, Version=0.30.1.0, Culture=neutral, PublicKeyToken=afb0a02973931d96, processorArchitecture=MSIL">
<HintPath>..\packages\SharpCompress.0.23.0\lib\net45\SharpCompress.dll</HintPath> <HintPath>..\packages\SharpCompress.0.30.1\lib\net461\SharpCompress.dll</HintPath>
</Reference>
<Reference Include="Snappier, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a1b25124e6e13a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Snappier.1.0.0\lib\netstandard2.0\Snappier.dll</HintPath>
</Reference> </Reference>
<Reference Include="Snappy.NET, Version=1.1.1.8, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Snappy.NET, Version=1.1.1.8, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Snappy.NET.1.1.1.8\lib\net45\Snappy.NET.dll</HintPath> <HintPath>..\packages\Snappy.NET.1.1.1.8\lib\net45\Snappy.NET.dll</HintPath>
@@ -68,18 +84,39 @@
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath> <HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="System.IO, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.IO.4.3.0\lib\net462\System.IO.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http, Version=4.1.1.3, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <Reference Include="System.Net.Http, Version=4.1.1.3, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll</HintPath> <HintPath>..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <Reference Include="System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll</HintPath> <HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath> <HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.Security.AccessControl, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.AccessControl.5.0.0\lib\net461\System.Security.AccessControl.dll</HintPath>
</Reference>
<Reference Include="System.Security.Cryptography.Algorithms, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <Reference Include="System.Security.Cryptography.Algorithms, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll</HintPath> <HintPath>..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll</HintPath>
</Reference> </Reference>
@@ -92,9 +129,21 @@
<Reference Include="System.Security.Cryptography.X509Certificates, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <Reference Include="System.Security.Cryptography.X509Certificates, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll</HintPath> <HintPath>..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.Security.Principal.Windows, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Principal.Windows.5.0.0\lib\net461\System.Security.Principal.Windows.dll</HintPath>
</Reference>
<Reference Include="System.Text.Encoding.CodePages, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.Encoding.CodePages.5.0.0\lib\net461\System.Text.Encoding.CodePages.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath> <HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
</Reference> </Reference>
<Reference Include="ZstdSharp, Version=0.7.3.0, Culture=neutral, PublicKeyToken=8d151af33a4ad5cf, processorArchitecture=MSIL">
<HintPath>..\packages\ZstdSharp.Port.0.7.3\lib\net461\ZstdSharp.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="CRUDObjectIdTests.cs" /> <Compile Include="CRUDObjectIdTests.cs" />
@@ -118,17 +167,23 @@
<None Include="App.config"> <None Include="App.config">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</None> </None>
<None Include="libmongocrypt.dylib" />
<None Include="libmongocrypt.so" />
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Core\Compression\Snappy\lib\win\snappy32.dll" /> <ProjectReference Include="..\MongoDbGenericRepository\MongoDbGenericRepository.csproj">
<Content Include="Core\Compression\Snappy\lib\win\snappy64.dll" /> <Project>{efc776c4-2af3-440c-be80-3fbe335817a5}</Project>
<Content Include="Core\Compression\Zstandard\lib\win\libzstd.dll" /> <Name>MongoDbGenericRepository</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\AWSSDK.SecurityToken.3.7.100.14\analyzers\dotnet\cs\AWSSDK.SecurityToken.CodeAnalysis.dll" />
</ItemGroup>
<ItemGroup>
<Content Include="libmongocrypt.dylib" />
<Content Include="libmongocrypt.so" />
<Content Include="mongocrypt.dll" /> <Content Include="mongocrypt.dll" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
@@ -136,11 +191,9 @@
<PropertyGroup> <PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup> </PropertyGroup>
<Error Condition="!Exists('..\packages\MongoDB.Libmongocrypt.1.2.2\build\MongoDB.Libmongocrypt.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MongoDB.Libmongocrypt.1.2.2\build\MongoDB.Libmongocrypt.targets'))" />
<Error Condition="!Exists('..\packages\NUnit.3.13.2\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.13.2\build\NUnit.props'))" /> <Error Condition="!Exists('..\packages\NUnit.3.13.2\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.13.2\build\NUnit.props'))" />
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.4.0.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.4.0.0\build\net35\NUnit3TestAdapter.props'))" /> <Error Condition="!Exists('..\packages\NUnit3TestAdapter.4.0.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.4.0.0\build\net35\NUnit3TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MongoDB.Driver.Core.2.13.2\build\MongoDB.Driver.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MongoDB.Driver.Core.2.13.2\build\MongoDB.Driver.Core.targets'))" /> <Error Condition="!Exists('..\packages\MongoDB.Libmongocrypt.1.9.0\build\MongoDB.Libmongocrypt.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MongoDB.Libmongocrypt.1.9.0\build\MongoDB.Libmongocrypt.targets'))" />
</Target> </Target>
<Import Project="..\packages\MongoDB.Libmongocrypt.1.2.2\build\MongoDB.Libmongocrypt.targets" Condition="Exists('..\packages\MongoDB.Libmongocrypt.1.2.2\build\MongoDB.Libmongocrypt.targets')" /> <Import Project="..\packages\MongoDB.Libmongocrypt.1.9.0\build\MongoDB.Libmongocrypt.targets" Condition="Exists('..\packages\MongoDB.Libmongocrypt.1.9.0\build\MongoDB.Libmongocrypt.targets')" />
<Import Project="..\packages\MongoDB.Driver.Core.2.13.2\build\MongoDB.Driver.Core.targets" Condition="Exists('..\packages\MongoDB.Driver.Core.2.13.2\build\MongoDB.Driver.Core.targets')" />
</Project> </Project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
+21 -7
View File
@@ -1,24 +1,38 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="MongoDB.Driver.Core" version="2.25.0" targetFramework="net48" />
<package id="MongoDB.Libmongocrypt" version="1.9.0" targetFramework="net48" />
<package id="AWSSDK.Core" version="3.7.100.14" targetFramework="net48" />
<package id="AWSSDK.SecurityToken" version="3.7.100.14" targetFramework="net48" />
<package id="Crc32C.NET" version="1.0.5.0" targetFramework="net461" /> <package id="Crc32C.NET" version="1.0.5.0" targetFramework="net461" />
<package id="DnsClient" version="1.4.0" targetFramework="net461" /> <package id="DnsClient" version="1.6.1" targetFramework="net48" />
<package id="MongoDB.Bson" version="2.13.2" targetFramework="net461" /> <package id="Microsoft.Bcl.AsyncInterfaces" version="5.0.0" targetFramework="net48" />
<package id="MongoDB.Driver" version="2.13.2" targetFramework="net461" /> <package id="Microsoft.Extensions.Logging.Abstractions" version="2.0.0" targetFramework="net48" />
<package id="MongoDB.Driver.Core" version="2.13.2" targetFramework="net461" /> <package id="Microsoft.Win32.Registry" version="5.0.0" targetFramework="net48" />
<package id="MongoDB.Libmongocrypt" version="1.2.2" targetFramework="net461" /> <package id="MongoDB.Bson" version="2.25.0" targetFramework="net48" />
<package id="MongoDbGenericRepository" version="1.4.8" targetFramework="net461" /> <package id="MongoDB.Driver" version="2.25.0" targetFramework="net48" />
<package id="NUnit" version="3.13.2" targetFramework="net461" /> <package id="NUnit" version="3.13.2" targetFramework="net461" />
<package id="NUnit.ConsoleRunner" version="3.12.0" targetFramework="net461" /> <package id="NUnit.ConsoleRunner" version="3.12.0" targetFramework="net461" />
<package id="NUnit3TestAdapter" version="4.0.0" targetFramework="net461" /> <package id="NUnit3TestAdapter" version="4.0.0" targetFramework="net461" />
<package id="SharpCompress" version="0.23.0" targetFramework="net461" /> <package id="SharpCompress" version="0.30.1" targetFramework="net48" />
<package id="Snappier" version="1.0.0" targetFramework="net48" />
<package id="Snappy.NET" version="1.1.1.8" targetFramework="net461" /> <package id="Snappy.NET" version="1.1.1.8" targetFramework="net461" />
<package id="System.Buffers" version="4.5.1" targetFramework="net461" /> <package id="System.Buffers" version="4.5.1" targetFramework="net461" />
<package id="System.IO" version="4.3.0" targetFramework="net48" />
<package id="System.Memory" version="4.5.5" targetFramework="net48" />
<package id="System.Net.Http" version="4.3.4" targetFramework="net461" /> <package id="System.Net.Http" version="4.3.4" targetFramework="net461" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" />
<package id="System.Runtime" version="4.3.0" targetFramework="net48" />
<package id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" targetFramework="net461" /> <package id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" targetFramework="net461" />
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net461" /> <package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net461" />
<package id="System.Security.AccessControl" version="5.0.0" targetFramework="net48" />
<package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net461" /> <package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net461" />
<package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net461" /> <package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net461" />
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net461" /> <package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net461" />
<package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net461" /> <package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net461" />
<package id="System.Security.Principal.Windows" version="5.0.0" targetFramework="net48" />
<package id="System.Text.Encoding.CodePages" version="5.0.0" targetFramework="net48" />
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net48" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net461" /> <package id="System.ValueTuple" version="4.5.0" targetFramework="net461" />
<package id="ZstdSharp.Port" version="0.7.3" targetFramework="net48" />
</packages> </packages>
@@ -0,0 +1,59 @@
using System;
using System.Collections.Concurrent;
using MongoDB.Bson.Serialization;
namespace MongoDbGenericRepository.Internals
{
/// <summary>
/// An <see cref="IBsonSerializationProvider"/> that can handle multiple serializer registration calls.
/// </summary>
internal class RepositorySerializationProvider : IBsonSerializationProvider
{
private static volatile RepositorySerializationProvider _instance;
private static readonly object LockObject = new object();
private readonly ConcurrentDictionary<Type, IBsonSerializer> _cache;
private RepositorySerializationProvider()
{
_cache = new ConcurrentDictionary<Type, IBsonSerializer>();
}
public static RepositorySerializationProvider Instance
{
get
{
if (_instance == null)
{
lock (LockObject)
{
if (_instance == null)
{
_instance = new RepositorySerializationProvider();
BsonSerializer.RegisterSerializationProvider(_instance);
}
}
}
return _instance;
}
}
/// <inheritdoc />
public IBsonSerializer GetSerializer(Type type)
{
if (type == null)
{
throw new ArgumentNullException(nameof(type));
}
return _cache.TryGetValue(type, out var serializer) ? serializer : null;
}
internal void RegisterSerializer<T>(IBsonSerializer<T> serializer) =>
RegisterSerializer(typeof(T), serializer);
internal void RegisterSerializer(Type type, IBsonSerializer serializer) =>
_cache.TryAdd(type, serializer);
}
}
+14 -7
View File
@@ -3,6 +3,9 @@ using MongoDbGenericRepository.Attributes;
using MongoDbGenericRepository.Utils; using MongoDbGenericRepository.Utils;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Serializers;
using MongoDbGenericRepository.Internals;
namespace MongoDbGenericRepository namespace MongoDbGenericRepository
{ {
@@ -21,7 +24,6 @@ namespace MongoDbGenericRepository
/// </summary> /// </summary>
public IMongoDatabase Database { get; } public IMongoDatabase Database { get; }
/// <summary> /// <summary>
/// The constructor of the MongoDbContext, it needs an object implementing <see cref="IMongoDatabase"/>. /// The constructor of the MongoDbContext, it needs an object implementing <see cref="IMongoDatabase"/>.
/// </summary> /// </summary>
@@ -90,9 +92,14 @@ namespace MongoDbGenericRepository
/// Sets the Guid representation of the MongoDB Driver. /// Sets the Guid representation of the MongoDB Driver.
/// </summary> /// </summary>
/// <param name="guidRepresentation">The new value of the GuidRepresentation</param> /// <param name="guidRepresentation">The new value of the GuidRepresentation</param>
public virtual void SetGuidRepresentation(MongoDB.Bson.GuidRepresentation guidRepresentation) public virtual void SetGuidRepresentation(GuidRepresentation guidRepresentation)
{ {
MongoDefaults.GuidRepresentation = guidRepresentation; // GuidRepresentation and GuidRepresentationMode will be removed in the next major release of the MongoDB Driver.
// We can safely replace this with RepositorySerializationProvider.Instance.RegisterSerializer once we upgrade to the next major release.
#pragma warning disable CS0618
BsonDefaults.GuidRepresentationMode = GuidRepresentationMode.V3;
RepositorySerializationProvider.Instance.RegisterSerializer(new GuidSerializer(guidRepresentation));
#pragma warning restore CS0618
} }
/// <summary> /// <summary>
@@ -103,8 +110,8 @@ namespace MongoDbGenericRepository
protected virtual string GetAttributeCollectionName<TDocument>() protected virtual string GetAttributeCollectionName<TDocument>()
{ {
return (typeof(TDocument).GetTypeInfo() return (typeof(TDocument).GetTypeInfo()
.GetCustomAttributes(typeof(CollectionNameAttribute)) .GetCustomAttributes(typeof(CollectionNameAttribute))
.FirstOrDefault() as CollectionNameAttribute)?.Name; .FirstOrDefault() as CollectionNameAttribute)?.Name;
} }
/// <summary> /// <summary>
@@ -114,7 +121,7 @@ namespace MongoDbGenericRepository
protected virtual void InitializeGuidRepresentation() protected virtual void InitializeGuidRepresentation()
{ {
// by default, avoid legacy UUID representation: use Binary 0x04 subtype. // by default, avoid legacy UUID representation: use Binary 0x04 subtype.
MongoDefaults.GuidRepresentation = MongoDB.Bson.GuidRepresentation.Standard; SetGuidRepresentation(GuidRepresentation.Standard);
} }
/// <summary> /// <summary>
@@ -143,4 +150,4 @@ namespace MongoDbGenericRepository
return (typeof(TDocument).Name.Pluralize()).Camelize(); return (typeof(TDocument).Name.Pluralize()).Camelize();
} }
} }
} }
@@ -4,7 +4,7 @@
<TargetFrameworks>net472;netstandard2.0;</TargetFrameworks> <TargetFrameworks>net472;netstandard2.0;</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageId>MongoDbGenericRepository</PackageId> <PackageId>MongoDbGenericRepository</PackageId>
<PackageVersion>1.4.8</PackageVersion> <PackageVersion>1.6.0</PackageVersion>
<Authors>Alexandre Spieser</Authors> <Authors>Alexandre Spieser</Authors>
<PackageTitle>MongoDb Generic Repository</PackageTitle> <PackageTitle>MongoDb Generic Repository</PackageTitle>
<Description>A generic repository implementation using the MongoDB C# Sharp 2.0 driver.</Description> <Description>A generic repository implementation using the MongoDB C# Sharp 2.0 driver.</Description>
@@ -12,10 +12,10 @@
<PackageProjectUrl>http://www.opensource.org/licenses/mit-license.php</PackageProjectUrl> <PackageProjectUrl>http://www.opensource.org/licenses/mit-license.php</PackageProjectUrl>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> <PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageReleaseNotes>Release notes are at https://github.com/alexandre-spieser/mongodb-generic-repository/releases </PackageReleaseNotes> <PackageReleaseNotes>Release notes are at https://github.com/alexandre-spieser/mongodb-generic-repository/releases </PackageReleaseNotes>
<Copyright>Copyright 2021 (c) Alexandre Spieser. All rights reserved.</Copyright> <Copyright>Copyright 2023 (c) Alexandre Spieser. All rights reserved.</Copyright>
<PackageTags>MongoDb Repository Generic NoSql</PackageTags> <PackageTags>MongoDb Repository Generic NoSql</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.4.8</Version> <Version>1.6.0</Version>
<RepositoryUrl>https://github.com/alexandre-spieser/mongodb-generic-repository</RepositoryUrl> <RepositoryUrl>https://github.com/alexandre-spieser/mongodb-generic-repository</RepositoryUrl>
<RepositoryType>Git</RepositoryType> <RepositoryType>Git</RepositoryType>
</PropertyGroup> </PropertyGroup>
@@ -25,7 +25,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.15.0" /> <PackageReference Include="MongoDB.Driver" Version="2.25.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>