Skip to content

Commit

Permalink
concurrency handling
Browse files Browse the repository at this point in the history
  • Loading branch information
phongnguyend committed Jul 29, 2022
1 parent ac413f3 commit e3a8941
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace ClassifiedAds.Domain.Repositories
{
public interface IConcurrencyHandler<TEntity>
{
void SetRowVersion(TEntity entity, byte[] version);

bool IsDbUpdateConcurrencyException(Exception ex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace ClassifiedAds.Domain.Repositories
{
public interface IRepository<TEntity, TKey>
public interface IRepository<TEntity, TKey> : IConcurrencyHandler<TEntity>
where TEntity : AggregateRoot<TKey>
{
IUnitOfWork UnitOfWork { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<PackageReference Include="DinkToPdf" Version="1.0.8" />
<PackageReference Include="Google.Protobuf" Version="3.19.1" />
<PackageReference Include="Grpc.Net.Client" Version="2.40.0" />
<PackageReference Include="EntityFrameworkCore.SqlServer.SimpleBulks" Version="6.4.0" />
<PackageReference Include="EntityFrameworkCore.SqlServer.SimpleBulks" Version="6.5.0" />
<PackageReference Include="IdentityModel" Version="5.2.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.19.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,15 @@ public void BulkMerge(IEnumerable<TEntity> entities, Expression<Func<TEntity, ob
{
_dbContext.BulkMerge(entities, idSelector, updateColumnNamesSelector, insertColumnNamesSelector);
}

public void SetRowVersion(TEntity entity, byte[] version)
{
_dbContext.Entry(entity).OriginalValues[nameof(entity.RowVersion)] = version;
}

public bool IsDbUpdateConcurrencyException(Exception ex)
{
return ex is DbUpdateConcurrencyException;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace ClassifiedAds.Domain.Repositories
{
public interface IConcurrencyHandler<TEntity>
{
void SetRowVersion(TEntity entity, byte[] version);

bool IsDbUpdateConcurrencyException(Exception ex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace ClassifiedAds.Domain.Repositories
{
public interface IRepository<TEntity, TKey>
public interface IRepository<TEntity, TKey> : IConcurrencyHandler<TEntity>
where TEntity : AggregateRoot<TKey>
{
IUnitOfWork UnitOfWork { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<PackageReference Include="CsvHelper" Version="27.2.0" />
<PackageReference Include="Dapper.StrongName" Version="2.0.123" />
<PackageReference Include="DinkToPdf" Version="1.0.8" />
<PackageReference Include="EntityFrameworkCore.SqlServer.SimpleBulks" Version="6.4.0" />
<PackageReference Include="EntityFrameworkCore.SqlServer.SimpleBulks" Version="6.5.0" />
<PackageReference Include="IdentityModel" Version="5.2.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.19.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,15 @@ public void BulkMerge(IEnumerable<TEntity> entities, Expression<Func<TEntity, ob
{
_dbContext.BulkMerge(entities, idSelector, updateColumnNamesSelector, insertColumnNamesSelector);
}

public void SetRowVersion(TEntity entity, byte[] version)
{
_dbContext.Entry(entity).OriginalValues[nameof(entity.RowVersion)] = version;
}

public bool IsDbUpdateConcurrencyException(Exception ex)
{
return ex is DbUpdateConcurrencyException;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace ClassifiedAds.Domain.Repositories
{
public interface IConcurrencyHandler<TEntity>
{
void SetRowVersion(TEntity entity, byte[] version);

bool IsDbUpdateConcurrencyException(Exception ex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace ClassifiedAds.Domain.Repositories
{
public interface IRepository<TEntity, TKey>
public interface IRepository<TEntity, TKey> : IConcurrencyHandler<TEntity>
where TEntity : AggregateRoot<TKey>
{
IUnitOfWork UnitOfWork { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EntityFrameworkCore.SqlServer.SimpleBulks" Version="6.4.0" />
<PackageReference Include="EntityFrameworkCore.SqlServer.SimpleBulks" Version="6.5.0" />
<PackageReference Include="IdentityServer4" Version="4.1.2" />
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="4.1.2" />
<PackageReference Include="IdentityServer4.EntityFramework" Version="4.1.2" />
Expand Down
10 changes: 10 additions & 0 deletions src/Monolith/ClassifiedAds.Persistence/Repositories/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,15 @@ public void BulkMerge(IEnumerable<T> entities, Expression<Func<T, object>> idSel
{
_dbContext.BulkMerge(entities, idSelector, updateColumnNamesSelector, insertColumnNamesSelector);
}

public void SetRowVersion(T entity, byte[] version)
{
_dbContext.Entry(entity).OriginalValues[nameof(entity.RowVersion)] = version;
}

public bool IsDbUpdateConcurrencyException(Exception ex)
{
return ex is DbUpdateConcurrencyException;
}
}
}

0 comments on commit e3a8941

Please sign in to comment.