@@ -41,6 +41,7 @@ public sealed class MongoClient : IMongoClient
41
41
private readonly IClusterInternal _cluster ;
42
42
#pragma warning restore CA2213 // Disposable fields should be disposed
43
43
private readonly IAutoEncryptionLibMongoCryptController _libMongoCryptController ;
44
+ private readonly Func < IMongoClient , IOperationExecutor > _operationExecutorFactory ;
44
45
private readonly IOperationExecutor _operationExecutor ;
45
46
private readonly MongoClientSettings _settings ;
46
47
private readonly ILogger < LogCategories . Client > _logger ;
@@ -61,26 +62,9 @@ public MongoClient()
61
62
/// </summary>
62
63
/// <param name="settings">The settings.</param>
63
64
public MongoClient ( MongoClientSettings settings )
65
+ : this ( client => new OperationExecutor ( client ) , settings )
64
66
{
65
- _settings = Ensure . IsNotNull ( settings , nameof ( settings ) ) . FrozenCopy ( ) ;
66
- _logger = _settings . LoggingSettings ? . CreateLogger < LogCategories . Client > ( ) ;
67
67
68
- _cluster = _settings . ClusterSource . Get ( _settings . ToClusterKey ( ) ) ;
69
- _operationExecutor = new OperationExecutor ( this ) ;
70
- _readOperationOptions = new ( DefaultReadPreference : _settings . ReadPreference ) ;
71
- _writeOperationOptions = new ( ) ;
72
-
73
- if ( settings . AutoEncryptionOptions != null )
74
- {
75
- _libMongoCryptController =
76
- MongoClientSettings . Extensions . AutoEncryptionProvider . CreateAutoCryptClientController ( this , settings . AutoEncryptionOptions ) ;
77
-
78
- _settings . LoggingSettings ? . CreateLogger < LogCategories . Client > ( ) ? . LogTrace (
79
- StructuredLogTemplateProviders . TopologyId_Message_SharedLibraryVersion ,
80
- _cluster . ClusterId ,
81
- "CryptClient created. Configured shared library version: " ,
82
- _libMongoCryptController . CryptSharedLibraryVersion ( ) ?? "None" ) ;
83
- }
84
68
}
85
69
86
70
/// <summary>
@@ -101,10 +85,27 @@ public MongoClient(string connectionString)
101
85
{
102
86
}
103
87
104
- internal MongoClient ( IOperationExecutor operationExecutor , MongoClientSettings settings )
105
- : this ( settings )
88
+ internal MongoClient ( Func < IMongoClient , IOperationExecutor > operationExecutorFactory , MongoClientSettings settings )
106
89
{
107
- _operationExecutor = new OperationExecutorWrapper ( operationExecutor ) ;
90
+ _operationExecutorFactory = Ensure . IsNotNull ( operationExecutorFactory , nameof ( operationExecutorFactory ) ) ;
91
+ _settings = Ensure . IsNotNull ( settings , nameof ( settings ) ) . FrozenCopy ( ) ;
92
+ _logger = _settings . LoggingSettings ? . CreateLogger < LogCategories . Client > ( ) ;
93
+ _cluster = _settings . ClusterSource . Get ( _settings . ToClusterKey ( ) ) ;
94
+ _operationExecutor = _operationExecutorFactory ( this ) ;
95
+ _readOperationOptions = new ( DefaultReadPreference : _settings . ReadPreference ) ;
96
+ _writeOperationOptions = new ( ) ;
97
+
98
+ if ( settings . AutoEncryptionOptions != null )
99
+ {
100
+ _libMongoCryptController =
101
+ MongoClientSettings . Extensions . AutoEncryptionProvider . CreateAutoCryptClientController ( this , settings . AutoEncryptionOptions ) ;
102
+
103
+ _settings . LoggingSettings ? . CreateLogger < LogCategories . Client > ( ) ? . LogTrace (
104
+ StructuredLogTemplateProviders . TopologyId_Message_SharedLibraryVersion ,
105
+ _cluster . ClusterId ,
106
+ "CryptClient created. Configured shared library version: " ,
107
+ _libMongoCryptController . CryptSharedLibraryVersion ( ) ?? "None" ) ;
108
+ }
108
109
}
109
110
110
111
// public properties
@@ -442,7 +443,7 @@ public IMongoClient WithReadConcern(ReadConcern readConcern)
442
443
443
444
var newSettings = Settings . Clone ( ) ;
444
445
newSettings . ReadConcern = readConcern ;
445
- return new MongoClient ( _operationExecutor , newSettings ) ;
446
+ return new MongoClient ( _operationExecutorFactory , newSettings ) ;
446
447
}
447
448
448
449
/// <inheritdoc/>
@@ -454,7 +455,7 @@ public IMongoClient WithReadPreference(ReadPreference readPreference)
454
455
455
456
var newSettings = Settings . Clone ( ) ;
456
457
newSettings . ReadPreference = readPreference ;
457
- return new MongoClient ( _operationExecutor , newSettings ) ;
458
+ return new MongoClient ( _operationExecutorFactory , newSettings ) ;
458
459
}
459
460
460
461
/// <inheritdoc/>
@@ -466,7 +467,7 @@ public IMongoClient WithWriteConcern(WriteConcern writeConcern)
466
467
467
468
var newSettings = Settings . Clone ( ) ;
468
469
newSettings . WriteConcern = writeConcern ;
469
- return new MongoClient ( _operationExecutor , newSettings ) ;
470
+ return new MongoClient ( _operationExecutorFactory , newSettings ) ;
470
471
}
471
472
472
473
// private methods
0 commit comments