@@ -73,20 +73,23 @@ public interface IExternalIdentityRepository
7373public class RdbExternalIdentityRepository : IExternalIdentityRepository
7474{
7575 private readonly ILogger < RdbExternalIdentityRepository > _logger ;
76- private readonly SyncnetDbContext _db ;
76+ private readonly IDbContextFactory < SyncnetDbContext > _dbContextFactory ;
77+
78+ //private readonly SyncnetDbContext _db;
7779
7880 public RdbExternalIdentityRepository (
7981 ILogger < RdbExternalIdentityRepository > logger ,
80- SyncnetDbContext db
82+ IDbContextFactory < SyncnetDbContext > dbContextFactory
8183
8284 )
8385 {
8486 _logger = logger ;
85- _db = db ;
87+ _dbContextFactory = dbContextFactory ;
8688 }
8789 public async Task < Guid > GetOrCreate ( IdProviderType idProviderType , string idExternal )
8890 {
89- PlayerExternalIdentities ? entity = await _db . ExternalIdentities
91+ var dbContext = _dbContextFactory . CreateDbContext ( ) ;
92+ PlayerExternalIdentities ? entity = await dbContext . ExternalIdentities
9093 . SingleOrDefaultAsync ( p =>
9194 p . IdProvider == idProviderType &&
9295 p . IdExternal == idExternal ) ;
@@ -102,15 +105,15 @@ public async Task<Guid> GetOrCreate(IdProviderType idProviderType, string idExte
102105 SyncnetId = Guid . NewGuid ( ) ,
103106 Created = DateTime . UtcNow
104107 } ;
105- await _db . ExternalIdentities . AddAsync ( entity ) ;
106- await _db . SaveChangesAsync ( ) ;
108+ await dbContext . ExternalIdentities . AddAsync ( entity ) ;
109+ await dbContext . SaveChangesAsync ( ) ;
107110 }
108111 catch ( DbUpdateException ex ) when ( ex . InnerException is PostgresException pg )
109112 {
110113 if ( pg . SqlState == PostgresErrorCodes . UniqueViolation )
111114 {
112115 // Reload the entity.
113- entity = await _db . ExternalIdentities
116+ entity = await dbContext . ExternalIdentities
114117 . SingleAsync ( p =>
115118 p . IdProvider == idProviderType &&
116119 p . IdExternal == idExternal ) ;
@@ -128,7 +131,9 @@ public async Task<Guid> GetOrCreate(IdProviderType idProviderType, string idExte
128131
129132 public async Task Remove ( IdProviderType idProviderType , string idExternal )
130133 {
131- _ = await _db . ExternalIdentities
134+ var dbContext = _dbContextFactory . CreateDbContext ( ) ;
135+
136+ _ = await dbContext . ExternalIdentities
132137 . Where ( w =>
133138 w . IdProvider == idProviderType &&
134139 w . IdExternal == idExternal )
0 commit comments