Skip to content

Commit

Permalink
Fixed up MongoDB unit of work
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuck committed Sep 15, 2023
1 parent 79cf016 commit 6fd4733
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.5</Version>
<Version>6.3.6</Version>
<Description>An implementation of YuckQi.Data for Amazon DynamoDB databases.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public static class DocumentModelExtensions
{
private const String DefaultObjectIdPropertyName = "_id";

private static readonly ConcurrentDictionary<Type, String> CollectionNameByType = new();
private static readonly ConcurrentDictionary<Type, String> DatabaseNameByType = new();
private static readonly ConcurrentDictionary<Type, PropertyInfo> IdentifierByType = new();
private static readonly ConcurrentDictionary<Type, String> CollectionNameByType = new ();
private static readonly ConcurrentDictionary<Type, String> DatabaseNameByType = new ();
private static readonly ConcurrentDictionary<Type, PropertyInfo> IdentifierByType = new ();

public static String? GetCollectionName(this Type? type) => type != null ? CollectionNameByType.GetOrAdd(type, identifier => GetCollectionAttribute(identifier)?.Name ?? identifier.Name) : null;

Expand Down
10 changes: 6 additions & 4 deletions src/YuckQi.Data.DocumentDb.MongoDb/UnitOfWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace YuckQi.Data.DocumentDb.MongoDb;
public class UnitOfWork : IUnitOfWork<IClientSessionHandle>
{
private readonly IMongoClient _client;
private readonly Object _lock = new();
private readonly Object _lock = new ();
private readonly ClientSessionOptions? _options;
private Lazy<IClientSessionHandle>? _session;

Expand All @@ -24,7 +24,9 @@ public void Dispose()
if (_session == null)
return;

Scope.AbortTransaction();
if (Scope.IsInTransaction)
Scope.AbortTransaction();

Scope.Dispose();

_session = null;
Expand All @@ -37,8 +39,8 @@ public void SaveChanges()
if (_session == null)
throw new InvalidOperationException();

Scope.CommitTransaction();
Scope.Dispose();
if (Scope.IsInTransaction)
Scope.CommitTransaction();

_session = new Lazy<IClientSessionHandle>(() => _client.StartSession(_options));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.5</Version>
<Version>6.3.6</Version>
<Description>An implementation of YuckQi.Data for MongoDB databases.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/YuckQi.Data.MemDb/YuckQi.Data.MemDb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.5</Version>
<Version>6.3.6</Version>
<Description>An implementation of YuckQi.Data for a in-memory "database" (ConcurrentDictionary), ideal for rapid development without external dependencies.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.5</Version>
<Version>6.3.6</Version>
<Description>An implementation of YuckQi.Data for MySQL databases using Dapper and SimpleCRUD.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.5</Version>
<Version>6.3.6</Version>
<Description>An implementation of YuckQi.Data for Oracle databases using Dapper and SimpleCRUD.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.5</Version>
<Version>6.3.6</Version>
<Description>An implementation of YuckQi.Data for MSSQL databases using Dapper and SimpleCRUD.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/YuckQi.Data.Sql.Dapper/YuckQi.Data.Sql.Dapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.5</Version>
<Version>6.3.6</Version>
<Description>An implementation of YuckQi.Data for SQL databases using Dapper and SimpleCRUD.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.5</Version>
<Version>6.3.6</Version>
<Description>An implementation of YuckQi.Data for SQL databases using Entity Framework.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/YuckQi.Data/Sql/UnitOfWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class UnitOfWork<TScope, TDbConnection> : IUnitOfWork<TScope> where TScop
{
private TDbConnection? _connection;
private readonly IsolationLevel _isolation;
private readonly Object _lock = new();
private readonly Object _lock = new ();
private Lazy<TScope>? _transaction;

public TScope Scope => _transaction != null ? _transaction.Value : throw new NullReferenceException();
Expand Down
2 changes: 1 addition & 1 deletion src/YuckQi.Data/YuckQi.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.5</Version>
<Version>6.3.6</Version>
<Description>A .NET library of lightweight data access handlers which can be used to compose repositories and domain services.</Description>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down

0 comments on commit 6fd4733

Please sign in to comment.