@@ -19,6 +19,9 @@ namespace Thinktecture.EntityFrameworkCore.Infrastructure;
1919/// </summary>
2020public sealed class RelationalDbContextOptionsExtension : DbContextOptionsExtensionBase , IDbContextOptionsExtension
2121{
22+ private const int _DEFAULT_INITIAL_CAPACITY = 300 ;
23+ private const int _DEFAULT_MAXIMUM_RETAINED_CAPACITY = 4 * 1024 ;
24+
2225 private static readonly IRelationalDbContextComponentDecorator _defaultDecorator = new RelationalDbContextComponentDecorator ( ) ;
2326
2427 private readonly List < ServiceDescriptor > _serviceDescriptors ;
@@ -61,16 +64,16 @@ public IRelationalDbContextComponentDecorator ComponentDecorator
6164 /// </summary>
6265 public bool AddTenantDatabaseSupport { get ; set ; }
6366
64- private bool _addCustomRelationalQueryContextFactory ;
67+ private bool _useCustomRelationalQueryContextFactory ;
6568
6669 /// <summary>
6770 /// A custom factory is registered if <c>true</c>.
6871 /// The factory is required for some features.
6972 /// </summary>
70- public bool AddCustomRelationalQueryContextFactory
73+ public bool UseThinktectureRelationalQueryContextFactory
7174 {
72- get => _addCustomRelationalQueryContextFactory || AddTenantDatabaseSupport ;
73- set => _addCustomRelationalQueryContextFactory = value ;
75+ get => _useCustomRelationalQueryContextFactory || AddTenantDatabaseSupport ;
76+ set => _useCustomRelationalQueryContextFactory = value ;
7477 }
7578
7679 /// <summary>
@@ -80,7 +83,11 @@ public RelationalDbContextOptionsExtension()
8083 {
8184 _serviceDescriptors = new List < ServiceDescriptor > ( ) ;
8285 _evaluatableExpressionFilterPlugins = new List < Type > ( ) ;
83- _stringBuilderPolicy = new StringBuilderPooledObjectPolicy { InitialCapacity = 300 } ;
86+ _stringBuilderPolicy = new StringBuilderPooledObjectPolicy
87+ {
88+ InitialCapacity = _DEFAULT_INITIAL_CAPACITY ,
89+ MaximumRetainedCapacity = _DEFAULT_MAXIMUM_RETAINED_CAPACITY
90+ } ;
8491 }
8592
8693 /// <inheritdoc />
@@ -102,7 +109,7 @@ public void ApplyServices(IServiceCollection services)
102109
103110 services . Add < IMethodCallTranslatorPlugin , RelationalMethodCallTranslatorPlugin > ( GetLifetime < IMethodCallTranslatorPlugin > ( ) ) ;
104111
105- if ( AddCustomRelationalQueryContextFactory )
112+ if ( UseThinktectureRelationalQueryContextFactory )
106113 ComponentDecorator . RegisterDecorator < IQueryContextFactory > ( services , typeof ( ThinktectureRelationalQueryContextFactory < > ) ) ;
107114
108115 if ( _evaluatableExpressionFilterPlugins . Count > 0 )
@@ -228,17 +235,29 @@ private class RelationalDbContextOptionsExtensionInfo : DbContextOptionsExtensio
228235
229236 private string ? _logFragment ;
230237
231- public override string LogFragment => _logFragment ??= $@ "
232- {{
233- 'Custom RelationalQueryContextFactory'={ _extension . AddCustomRelationalQueryContextFactory } ,
234- 'Default schema respecting components added'={ _extension . AddSchemaRespectingComponents } ,
235- 'NestedTransactionsSupport'={ _extension . AddNestedTransactionsSupport } ,
236- 'RowNumberSupport'={ _extension . AddRowNumberSupport } ,
237- 'TenantDatabaseSupport'={ _extension . AddTenantDatabaseSupport } ,
238- 'Number of evaluatable expression filter plugins'={ _extension . _evaluatableExpressionFilterPlugins . Count } ,
239- 'Number of custom services'={ _extension . _serviceDescriptors . Count } ,
240- 'StringBuilderPool'= {{ InitialCapacity={ _extension . _stringBuilderPolicy . InitialCapacity } , MaximumRetainedCapacity={ _extension . _stringBuilderPolicy . MaximumRetainedCapacity } }}
241- }}" ;
238+ public override string LogFragment => _logFragment ??= CreateLogFragment ( ) ;
239+
240+ private string CreateLogFragment ( )
241+ {
242+ var sb = new StringBuilder ( ) ;
243+
244+ if ( _extension . AddSchemaRespectingComponents )
245+ sb . Append ( "SchemaRespectingComponents " ) ;
246+
247+ if ( _extension . AddNestedTransactionsSupport )
248+ sb . Append ( "NestedTransactionsSupport " ) ;
249+
250+ if ( _extension . AddRowNumberSupport )
251+ sb . Append ( "RowNumberSupport " ) ;
252+
253+ if ( _extension . AddTenantDatabaseSupport )
254+ sb . Append ( "TenantDatabaseSupport " ) ;
255+
256+ if ( _extension . _stringBuilderPolicy . InitialCapacity != _DEFAULT_INITIAL_CAPACITY || _extension . _stringBuilderPolicy . MaximumRetainedCapacity != _DEFAULT_MAXIMUM_RETAINED_CAPACITY )
257+ sb . Append ( "StringBuilderPool(InitialCapacity=" ) . Append ( _extension . _stringBuilderPolicy . InitialCapacity ) . Append ( ", MaximumRetainedCapacity=" ) . Append ( _extension . _stringBuilderPolicy . MaximumRetainedCapacity ) . Append ( ") " ) ;
258+
259+ return sb . ToString ( ) ;
260+ }
242261
243262 public RelationalDbContextOptionsExtensionInfo ( RelationalDbContextOptionsExtension extension )
244263 : base ( extension )
@@ -249,7 +268,7 @@ public RelationalDbContextOptionsExtensionInfo(RelationalDbContextOptionsExtensi
249268 public override int GetServiceProviderHashCode ( )
250269 {
251270 var hashCode = new HashCode ( ) ;
252- hashCode . Add ( _extension . AddCustomRelationalQueryContextFactory ) ;
271+ hashCode . Add ( _extension . UseThinktectureRelationalQueryContextFactory ) ;
253272 hashCode . Add ( _extension . AddSchemaRespectingComponents ) ;
254273 hashCode . Add ( _extension . AddNestedTransactionsSupport ) ;
255274 hashCode . Add ( _extension . AddTenantDatabaseSupport ) ;
@@ -273,7 +292,7 @@ public override bool ShouldUseSameServiceProvider(DbContextOptionsExtensionInfo
273292 if ( other is not RelationalDbContextOptionsExtensionInfo otherRelationalInfo )
274293 return false ;
275294
276- var areEqual = _extension . AddCustomRelationalQueryContextFactory == otherRelationalInfo . _extension . AddCustomRelationalQueryContextFactory
295+ var areEqual = _extension . UseThinktectureRelationalQueryContextFactory == otherRelationalInfo . _extension . UseThinktectureRelationalQueryContextFactory
277296 && _extension . AddSchemaRespectingComponents == otherRelationalInfo . _extension . AddSchemaRespectingComponents
278297 && _extension . AddNestedTransactionsSupport == otherRelationalInfo . _extension . AddNestedTransactionsSupport
279298 && _extension . AddTenantDatabaseSupport == otherRelationalInfo . _extension . AddTenantDatabaseSupport
@@ -333,7 +352,7 @@ private static int GetHashCode(ServiceDescriptor descriptor)
333352
334353 public override void PopulateDebugInfo ( IDictionary < string , string > debugInfo )
335354 {
336- debugInfo [ "Thinktecture:CustomRelationalQueryContextFactory" ] = _extension . AddCustomRelationalQueryContextFactory . ToString ( CultureInfo . InvariantCulture ) ;
355+ debugInfo [ "Thinktecture:CustomRelationalQueryContextFactory" ] = _extension . UseThinktectureRelationalQueryContextFactory . ToString ( CultureInfo . InvariantCulture ) ;
337356 debugInfo [ "Thinktecture:SchemaRespectingComponents" ] = _extension . AddSchemaRespectingComponents . ToString ( CultureInfo . InvariantCulture ) ;
338357 debugInfo [ "Thinktecture:NestedTransactionsSupport" ] = _extension . AddNestedTransactionsSupport . ToString ( CultureInfo . InvariantCulture ) ;
339358 debugInfo [ "Thinktecture:RowNumberSupport" ] = _extension . AddRowNumberSupport . ToString ( CultureInfo . InvariantCulture ) ;
0 commit comments