File tree Expand file tree Collapse file tree 2 files changed +7
-5
lines changed
src/framework/Luck.EntityFrameworkCore Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ namespace Luck.EntityFrameworkCore.DbContexts
8
8
/// <summary>
9
9
/// 类类上下文
10
10
/// </summary>
11
- public class LuckDbContextBase ( DbContextOptions options , IServiceProvider serviceProvider )
11
+ public abstract class LuckDbContextBase ( DbContextOptions options , IServiceProvider serviceProvider )
12
12
: DbContext ( options ) , ILuckDbContext
13
13
{
14
14
protected IServiceProvider ServiceProvider { get ; set ; } =
Original file line number Diff line number Diff line change @@ -9,13 +9,15 @@ namespace Luck.EntityFrameworkCore.UnitOfWorks
9
9
public class UnitOfWork : IUnitOfWork
10
10
{
11
11
//private readonly IDbContextFactory<ILuckDbContext> _dbContextFactory;
12
- protected LuckDbContextBase DbContext { get ; }
12
+ protected LuckDbContextBase DbContext => _luckDbContextBase ;
13
13
14
+ private readonly LuckDbContextBase _luckDbContextBase ;
15
+
14
16
private readonly ILogger < UnitOfWork > _logger ;
15
17
16
- public UnitOfWork ( ILogger < UnitOfWork > logger , ILuckDbContext dbContext )
18
+ public UnitOfWork ( ILogger < UnitOfWork > logger , LuckDbContextBase luckDbContextBase )
17
19
{
18
- DbContext = dbContext as LuckDbContextBase ?? throw new ArgumentNullException ( nameof ( ILuckDbContext ) ) ;
20
+ _luckDbContextBase = luckDbContextBase ?? throw new ArgumentNullException ( nameof ( ILuckDbContext ) ) ;
19
21
_logger = logger ?? throw new ArgumentNullException ( nameof ( ILogger ) ) ;
20
22
}
21
23
@@ -40,7 +42,7 @@ public async Task<int> CommitAsync(CancellationToken cancellationToken = default
40
42
41
43
public ILuckDbContext GetLuckDbContext ( )
42
44
{
43
- return DbContext ;
45
+ return _luckDbContextBase ;
44
46
}
45
47
}
46
48
}
You can’t perform that action at this time.
0 commit comments