1515
1616namespace DataAccessClient . EntityFrameworkCore . SqlServer
1717{
18- public abstract class SqlServerDbContext : DbContext , IDbContextPoolable
18+ public abstract class SqlServerDbContext : DbContext , IResettableService
1919 {
2020 private static readonly MethodInfo DbContextResetStateMethodInfo ;
2121 private static readonly MethodInfo DbContextResetStateAsyncMethodInfo ;
22- private static readonly MethodInfo DbContextResurrectMethodInfo ;
2322 internal static ConcurrentBag < Type > RegisteredDbContextTypes = new ConcurrentBag < Type > ( ) ;
2423 internal static ConcurrentDictionary < Type , List < Type > > RegisteredEntityTypesPerDbContexts = new ConcurrentDictionary < Type , List < Type > > ( ) ;
2524
@@ -31,9 +30,6 @@ static SqlServerDbContext()
3130 DbContextResetStateAsyncMethodInfo = typeof ( DbContext ) . GetMethod (
3231 $ "{ typeof ( IResettableService ) . FullName } .{ nameof ( IResettableService . ResetStateAsync ) } ",
3332 BindingFlags . Instance | BindingFlags . NonPublic ) ;
34- DbContextResurrectMethodInfo = typeof ( DbContext ) . GetMethod (
35- $ "{ typeof ( IDbContextPoolable ) . FullName } .{ nameof ( IDbContextPoolable . Resurrect ) } ",
36- BindingFlags . Instance | BindingFlags . NonPublic ) ;
3733 }
3834
3935 internal SqlServerDbContextExecutionContext ExecutionContext { get ; private set ; }
@@ -51,42 +47,11 @@ protected SqlServerDbContext(DbContextOptions options)
5147 _dbContextResetStateAsyncMethod =
5248 DbContextResetStateAsyncMethodInfo . CreateDelegate ( typeof ( Func < CancellationToken , Task > ) , this ) as
5349 Func < CancellationToken , Task > ;
54- _dbContextResurrectMethod =
55- DbContextResurrectMethodInfo . CreateDelegate ( typeof ( Action < DbContextPoolConfigurationSnapshot > ) , this ) as
56- Action < DbContextPoolConfigurationSnapshot > ;
57-
5850 DataAccessClientOptionsExtension = options . FindExtension < DataAccessClientOptionsExtension > ( ) ;
5951 }
6052
61- #region DbContextPooling
62-
63- // https://stackoverflow.com/questions/37310896/overriding-explicit-interface-implementations
64-
65- /// <summary>
66- /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
67- /// the same compatibility standards as public APIs. It may be changed or removed without notice in
68- /// any release. You should only use it directly in your code with extreme caution and knowing that
69- /// doing so can result in application failures when updating to a new Entity Framework Core release.
70- /// </summary>
71- void IDbContextPoolable . Resurrect ( DbContextPoolConfigurationSnapshot configurationSnapshot )
72- {
73- if ( _dbContextResurrectMethod != null )
74- {
75- _dbContextResurrectMethod . Invoke ( configurationSnapshot ) ;
76- }
77- else
78- {
79- throw new InvalidOperationException (
80- $ "Cannot find method { nameof ( IDbContextPoolable ) } .{ nameof ( IDbContextPoolable . Resurrect ) } on basetype DbContext of { GetType ( ) . FullName } ") ;
81- }
82- }
53+ #region IResettableService overrides to support DbContextPooling
8354
84- /// <summary>
85- /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
86- /// the same compatibility standards as public APIs. It may be changed or removed without notice in
87- /// any release. You should only use it directly in your code with extreme caution and knowing that
88- /// doing so can result in application failures when updating to a new Entity Framework Core release.
89- /// </summary>
9055 void IResettableService . ResetState ( )
9156 {
9257 ResetSqlServerDbContextState ( ) ;
@@ -102,13 +67,6 @@ void IResettableService.ResetState()
10267 }
10368 }
10469
105- /// <summary>
106- /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
107- /// the same compatibility standards as public APIs. It may be changed or removed without notice in
108- /// any release. You should only use it directly in your code with extreme caution and knowing that
109- /// doing so can result in application failures when updating to a new Entity Framework Core release.
110- /// </summary>
111- /// <param name="cancellationToken"> A <see cref="CancellationToken" /> to observe while waiting for the task to complete. </param>
11270 async Task IResettableService . ResetStateAsync ( CancellationToken cancellationToken )
11371 {
11472 ResetSqlServerDbContextState ( ) ;
0 commit comments