Skip to content

Commit c72bd31

Browse files
Release: Version 1.8.4 + Fix MongoDbContext double instantiation by reusing keyed registration (#27)
* fix: resolve DbContext from keyed registration to ensure single instance reuse. * New library version.
1 parent a99cb97 commit c72bd31

File tree

12 files changed

+45
-53
lines changed

12 files changed

+45
-53
lines changed

README.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,32 @@ If you like or are using this project to learn or start your solution, please gi
1212

1313
| Package | NuGet |
1414
|------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
15-
| MongoDB.Data.Infrastructure.Abstractions | [![Nuget](https://img.shields.io/badge/nuget-v1.8.3-blue) ![Nuget](https://img.shields.io/nuget/dt/MongoDB.Data.Infrastructure.Abstractions)](https://www.nuget.org/packages/MongoDB.Data.Infrastructure.Abstractions/1.8.3) |
16-
| MongoDB.Data.QueryBuilder.Abstractions | [![Nuget](https://img.shields.io/badge/nuget-v1.8.3-blue) ![Nuget](https://img.shields.io/nuget/dt/MongoDB.Data.QueryBuilder.Abstractions)](https://www.nuget.org/packages/MongoDB.Data.QueryBuilder.Abstractions/1.8.3) |
17-
| MongoDB.Data.Repository.Abstractions | [![Nuget](https://img.shields.io/badge/nuget-v1.8.3-blue) ![Nuget](https://img.shields.io/nuget/dt/MongoDB.Data.Repository.Abstractions)](https://www.nuget.org/packages/MongoDB.Data.Repository.Abstractions/1.8.3) |
18-
| MongoDB.Data.UnitOfWork.Abstractions | [![Nuget](https://img.shields.io/badge/nuget-v1.8.3-blue) ![Nuget](https://img.shields.io/nuget/dt/MongoDB.Data.UnitOfWork.Abstractions)](https://www.nuget.org/packages/MongoDB.Data.UnitOfWork.Abstractions/1.8.3) |
15+
| MongoDB.Data.Infrastructure.Abstractions | [![Nuget](https://img.shields.io/badge/nuget-v1.8.4-blue) ![Nuget](https://img.shields.io/nuget/dt/MongoDB.Data.Infrastructure.Abstractions)](https://www.nuget.org/packages/MongoDB.Data.Infrastructure.Abstractions/1.8.4) |
16+
| MongoDB.Data.QueryBuilder.Abstractions | [![Nuget](https://img.shields.io/badge/nuget-v1.8.4-blue) ![Nuget](https://img.shields.io/nuget/dt/MongoDB.Data.QueryBuilder.Abstractions)](https://www.nuget.org/packages/MongoDB.Data.QueryBuilder.Abstractions/1.8.4) |
17+
| MongoDB.Data.Repository.Abstractions | [![Nuget](https://img.shields.io/badge/nuget-v1.8.4-blue) ![Nuget](https://img.shields.io/nuget/dt/MongoDB.Data.Repository.Abstractions)](https://www.nuget.org/packages/MongoDB.Data.Repository.Abstractions/1.8.4) |
18+
| MongoDB.Data.UnitOfWork.Abstractions | [![Nuget](https://img.shields.io/badge/nuget-v1.8.4-blue) ![Nuget](https://img.shields.io/nuget/dt/MongoDB.Data.UnitOfWork.Abstractions)](https://www.nuget.org/packages/MongoDB.Data.UnitOfWork.Abstractions/1.8.4) |
1919
|------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
20-
| MongoDB.Data.Generators | [![Nuget](https://img.shields.io/badge/nuget-v1.8.3-blue) ![Nuget](https://img.shields.io/nuget/dt/MongoDB.Data.Generators)](https://www.nuget.org/packages/MongoDB.Data.Generators/1.8.3) |
21-
| MongoDB.Data.Infrastructure | [![Nuget](https://img.shields.io/badge/nuget-v1.8.3-blue) ![Nuget](https://img.shields.io/nuget/dt/MongoDB.Data.Infrastructure)](https://www.nuget.org/packages/MongoDB.Data.Infrastructure/1.8.3) |
22-
| MongoDB.Data.QueryBuilder | [![Nuget](https://img.shields.io/badge/nuget-v1.8.3-blue) ![Nuget](https://img.shields.io/nuget/dt/MongoDB.Data.QueryBuilder)](https://www.nuget.org/packages/MongoDB.Data.QueryBuilder/1.8.3) |
23-
| MongoDB.Data.Repository | [![Nuget](https://img.shields.io/badge/nuget-v1.8.3-blue) ![Nuget](https://img.shields.io/nuget/dt/MongoDB.Data.Repository)](https://www.nuget.org/packages/MongoDB.Data.Repository/1.8.3) |
24-
| MongoDB.Data.UnitOfWork | [![Nuget](https://img.shields.io/badge/nuget-v1.8.3-blue) ![Nuget](https://img.shields.io/nuget/dt/MongoDB.Data.UnitOfWork)](https://www.nuget.org/packages/MongoDB.Data.UnitOfWork/1.8.3) |
20+
| MongoDB.Data.Generators | [![Nuget](https://img.shields.io/badge/nuget-v1.8.4-blue) ![Nuget](https://img.shields.io/nuget/dt/MongoDB.Data.Generators)](https://www.nuget.org/packages/MongoDB.Data.Generators/1.8.4) |
21+
| MongoDB.Data.Infrastructure | [![Nuget](https://img.shields.io/badge/nuget-v1.8.4-blue) ![Nuget](https://img.shields.io/nuget/dt/MongoDB.Data.Infrastructure)](https://www.nuget.org/packages/MongoDB.Data.Infrastructure/1.8.4) |
22+
| MongoDB.Data.QueryBuilder | [![Nuget](https://img.shields.io/badge/nuget-v1.8.4-blue) ![Nuget](https://img.shields.io/nuget/dt/MongoDB.Data.QueryBuilder)](https://www.nuget.org/packages/MongoDB.Data.QueryBuilder/1.8.4) |
23+
| MongoDB.Data.Repository | [![Nuget](https://img.shields.io/badge/nuget-v1.8.4-blue) ![Nuget](https://img.shields.io/nuget/dt/MongoDB.Data.Repository)](https://www.nuget.org/packages/MongoDB.Data.Repository/1.8.4) |
24+
| MongoDB.Data.UnitOfWork | [![Nuget](https://img.shields.io/badge/nuget-v1.8.4-blue) ![Nuget](https://img.shields.io/nuget/dt/MongoDB.Data.UnitOfWork)](https://www.nuget.org/packages/MongoDB.Data.UnitOfWork/1.8.4) |
2525

2626
## Installation
2727

2828
MongoDB.DataAccess is available on Nuget.
2929

3030
```
31-
Install-Package MongoDB.Data.Infrastructure.Abstractions -Version 1.8.3
32-
Install-Package MongoDB.Data.QueryBuilder.Abstractions -Version 1.8.3
33-
Install-Package MongoDB.Data.Repository.Abstractions -Version 1.8.3
34-
Install-Package MongoDB.Data.UnitOfWork.Abstractions -Version 1.8.3
35-
36-
Install-Package MongoDB.Data.Generators -Version 1.8.3
37-
Install-Package MongoDB.Data.Infrastructure -Version 1.8.3
38-
Install-Package MongoDB.Data.QueryBuilder -Version 1.8.3
39-
Install-Package MongoDB.Data.Repository -Version 1.8.3
40-
Install-Package MongoDB.Data.UnitOfWork -Version 1.8.3
31+
Install-Package MongoDB.Data.Infrastructure.Abstractions -Version 1.8.4
32+
Install-Package MongoDB.Data.QueryBuilder.Abstractions -Version 1.8.4
33+
Install-Package MongoDB.Data.Repository.Abstractions -Version 1.8.4
34+
Install-Package MongoDB.Data.UnitOfWork.Abstractions -Version 1.8.4
35+
36+
Install-Package MongoDB.Data.Generators -Version 1.8.4
37+
Install-Package MongoDB.Data.Infrastructure -Version 1.8.4
38+
Install-Package MongoDB.Data.QueryBuilder -Version 1.8.4
39+
Install-Package MongoDB.Data.Repository -Version 1.8.4
40+
Install-Package MongoDB.Data.UnitOfWork -Version 1.8.4
4141
```
4242

4343
**P.S.: MongoDB.Data.UnitOfWork depends on the other packages, so installing this package is enough.**
@@ -126,6 +126,10 @@ services.AddMongoDbContext<IMongoDbContext, BloggingContext>(
126126

127127
// Register the UnitOfWork
128128
services.AddMongoDbUnitOfWork<BloggingContext>();
129+
130+
// Or
131+
services.AddMongoDbUnitOfWork<BloggingContext>("BloggingContext - TenantA");
132+
services.AddMongoDbUnitOfWork<BloggingContext>("BloggingContext - TenantB");
129133
```
130134

131135
After that, use the structure in your code like that:

src/MongoDB.Generators/MongoDB.Generators.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<RepositoryType>git</RepositoryType>
1717
<PackageTags>MongoDB;Mongo DB;mongo-db;Data;IdGenerators;Id Generators;id-generators</PackageTags>
1818
<PackageLicenseExpression>MIT</PackageLicenseExpression>
19-
<Version>1.8.3</Version>
19+
<Version>1.8.4</Version>
2020
<LangVersion>latest</LangVersion>
2121
</PropertyGroup>
2222

src/MongoDB.Infrastructure.Abstractions/MongoDB.Infrastructure.Abstractions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<RepositoryType>git</RepositoryType>
1818
<PackageTags>MongoDB;Mongo DB;mongo-db;Data;Infrastructure;Abstractions</PackageTags>
1919
<PackageLicenseExpression>MIT</PackageLicenseExpression>
20-
<Version>1.8.3</Version>
20+
<Version>1.8.4</Version>
2121
<LangVersion>latest</LangVersion>
2222
</PropertyGroup>
2323

src/MongoDB.Infrastructure/Extensions/MongoDbInfrastructureServiceCollectionExtensions.cs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ public static IServiceCollection AddMongoDbContext<TService, TImplementation>(
4848
services.TryAddSingleton<IMongoDbThrottlingSemaphoreFactory>(MongoDbThrottlingSemaphoreFactory.Instance);
4949

5050
services.Add(
51-
ServiceDescriptor.Describe(
51+
ServiceDescriptor.DescribeKeyed(
5252
typeof(TImplementation),
53-
provider => CreateDbContextInstance<TService, TImplementation>(
53+
dbContextOptions.DbContextId,
54+
(provider, key) => CreateDbContextInstance<TService, TImplementation>(
5455
provider,
5556
clientSettings,
5657
databaseName,
@@ -59,31 +60,25 @@ public static IServiceCollection AddMongoDbContext<TService, TImplementation>(
5960
serviceLifetime));
6061

6162
services.Add(
62-
ServiceDescriptor.DescribeKeyed(
63+
ServiceDescriptor.Describe(
6364
typeof(TImplementation),
64-
dbContextOptions.DbContextId,
65-
(provider, key) => CreateDbContextInstance<TService, TImplementation>(
66-
provider,
67-
clientSettings,
68-
databaseName,
69-
databaseSettings,
70-
dbContextOptions),
65+
provider => provider.GetRequiredKeyedService<TImplementation>(dbContextOptions.DbContextId),
7166
serviceLifetime));
7267

7368
if (typeof(TService) != typeof(TImplementation))
7469
{
75-
services.Add(
76-
ServiceDescriptor.Describe(
77-
typeof(TService),
78-
provider => provider.GetRequiredService<TImplementation>(),
79-
serviceLifetime));
80-
8170
services.Add(
8271
ServiceDescriptor.DescribeKeyed(
8372
typeof(TService),
8473
dbContextOptions.DbContextId,
8574
(provider, key) => provider.GetRequiredKeyedService<TImplementation>(key),
8675
serviceLifetime));
76+
77+
services.Add(
78+
ServiceDescriptor.Describe(
79+
typeof(TService),
80+
provider => provider.GetRequiredService<TImplementation>(),
81+
serviceLifetime));
8782
}
8883

8984
if (fluentConfigurationOptions?.EnableAssemblyScanning ?? false)

src/MongoDB.Infrastructure/MongoDB.Infrastructure.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<RepositoryType>git</RepositoryType>
1717
<PackageTags>MongoDB;Mongo DB;mongo-db;Data;Infrastructure</PackageTags>
1818
<PackageLicenseExpression>MIT</PackageLicenseExpression>
19-
<Version>1.8.3</Version>
19+
<Version>1.8.4</Version>
2020
<LangVersion>latest</LangVersion>
2121
</PropertyGroup>
2222

src/MongoDB.QueryBuilder.Abstractions/MongoDB.QueryBuilder.Abstractions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<RepositoryType>git</RepositoryType>
1818
<PackageTags>MongoDB;Mongo DB;mongo-db;Data;QueryBuilder;Query Builder;query-builder;Abstractions</PackageTags>
1919
<PackageLicenseExpression>MIT</PackageLicenseExpression>
20-
<Version>1.8.3</Version>
20+
<Version>1.8.4</Version>
2121
<LangVersion>latest</LangVersion>
2222
</PropertyGroup>
2323

src/MongoDB.QueryBuilder/MongoDB.QueryBuilder.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<RepositoryType>git</RepositoryType>
1717
<PackageTags>MongoDB;Mongo DB;mongo-db;Data;QueryBuilder;Query Builder;query-builder</PackageTags>
1818
<PackageLicenseExpression>MIT</PackageLicenseExpression>
19-
<Version>1.8.3</Version>
19+
<Version>1.8.4</Version>
2020
<LangVersion>latest</LangVersion>
2121
</PropertyGroup>
2222

src/MongoDB.Repository.Abstractions/MongoDB.Repository.Abstractions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<RepositoryType>git</RepositoryType>
1818
<PackageTags>MongoDB;Mongo DB;mongo-db;Data;Repository;Abstractions</PackageTags>
1919
<PackageLicenseExpression>MIT</PackageLicenseExpression>
20-
<Version>1.8.3</Version>
20+
<Version>1.8.4</Version>
2121
<LangVersion>latest</LangVersion>
2222
</PropertyGroup>
2323

src/MongoDB.Repository/MongoDB.Repository.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<RepositoryType>git</RepositoryType>
1717
<PackageTags>MongoDB;Mongo DB;mongo-db;Data;Repository</PackageTags>
1818
<PackageLicenseExpression>MIT</PackageLicenseExpression>
19-
<Version>1.8.3</Version>
19+
<Version>1.8.4</Version>
2020
<LangVersion>latest</LangVersion>
2121
</PropertyGroup>
2222

src/MongoDB.UnitOfWork.Abstractions/MongoDB.UnitOfWork.Abstractions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<RepositoryType>git</RepositoryType>
1818
<PackageTags>MongoDB;Mongo DB;mongo-db;Data;UnitOfWork;Unit Of Work;unit-of-work;Abstractions</PackageTags>
1919
<PackageLicenseExpression>MIT</PackageLicenseExpression>
20-
<Version>1.8.3</Version>
20+
<Version>1.8.4</Version>
2121
<LangVersion>latest</LangVersion>
2222
</PropertyGroup>
2323

0 commit comments

Comments
 (0)