diff --git a/R4.slnf b/R4.slnf index 4469743c86..0e555d8325 100644 --- a/R4.slnf +++ b/R4.slnf @@ -10,6 +10,9 @@ "src\\Microsoft.Health.Fhir.Azure\\Microsoft.Health.Fhir.Azure.csproj", "src\\Microsoft.Health.Fhir.Core.UnitTests\\Microsoft.Health.Fhir.Core.UnitTests.csproj", "src\\Microsoft.Health.Fhir.Core\\Microsoft.Health.Fhir.Core.csproj", + "src\Microsoft.Health.Fhir.CosmosDb.Core\Microsoft.Health.Fhir.CosmosDb.Core.csproj", + "src\Microsoft.Health.Fhir.CosmosDb.Initialization.UnitTests\Microsoft.Health.Fhir.CosmosDb.Initialization.UnitTests.csproj", + "src\Microsoft.Health.Fhir.CosmosDb.Initialization\Microsoft.Health.Fhir.CosmosDb.Initialization.csproj", "src\\Microsoft.Health.Fhir.CosmosDb.UnitTests\\Microsoft.Health.Fhir.CosmosDb.UnitTests.csproj", "src\\Microsoft.Health.Fhir.CosmosDb\\Microsoft.Health.Fhir.CosmosDb.csproj", "src\\Microsoft.Health.Fhir.R4.Api\\Microsoft.Health.Fhir.R4.Api.csproj", diff --git a/R5.slnf b/R5.slnf index b34a610a38..61bdc352fd 100644 --- a/R5.slnf +++ b/R5.slnf @@ -10,6 +10,9 @@ "src\\Microsoft.Health.Fhir.Azure\\Microsoft.Health.Fhir.Azure.csproj", "src\\Microsoft.Health.Fhir.Core.UnitTests\\Microsoft.Health.Fhir.Core.UnitTests.csproj", "src\\Microsoft.Health.Fhir.Core\\Microsoft.Health.Fhir.Core.csproj", + "src\Microsoft.Health.Fhir.CosmosDb.Core\Microsoft.Health.Fhir.CosmosDb.Core.csproj", + "src\Microsoft.Health.Fhir.CosmosDb.Initialization.UnitTests\Microsoft.Health.Fhir.CosmosDb.Initialization.UnitTests.csproj", + "src\Microsoft.Health.Fhir.CosmosDb.Initialization\Microsoft.Health.Fhir.CosmosDb.Initialization.csproj", "src\\Microsoft.Health.Fhir.CosmosDb.UnitTests\\Microsoft.Health.Fhir.CosmosDb.UnitTests.csproj", "src\\Microsoft.Health.Fhir.CosmosDb\\Microsoft.Health.Fhir.CosmosDb.csproj", "src\\Microsoft.Health.Fhir.R5.Api\\Microsoft.Health.Fhir.R5.Api.csproj", diff --git a/src/Microsoft.Health.Fhir.CosmosDb/Features/Storage/FhirCosmosClientInitializer.cs b/src/Microsoft.Health.Fhir.CosmosDb/Features/Storage/FhirCosmosClientInitializer.cs index 36ba1c1f11..ae54926ece 100644 --- a/src/Microsoft.Health.Fhir.CosmosDb/Features/Storage/FhirCosmosClientInitializer.cs +++ b/src/Microsoft.Health.Fhir.CosmosDb/Features/Storage/FhirCosmosClientInitializer.cs @@ -30,7 +30,7 @@ public class FhirCosmosClientInitializer : ICosmosClientInitializer private readonly ILogger _logger; private readonly Func> _requestHandlerFactory; private readonly RetryExceptionPolicyFactory _retryExceptionPolicyFactory; - private readonly ConcurrentDictionary _cosmosClients; + private static CosmosClient _cosmosClient; private readonly object _lockObject; public FhirCosmosClientInitializer( @@ -48,7 +48,6 @@ public FhirCosmosClientInitializer( _requestHandlerFactory = requestHandlerFactory; _retryExceptionPolicyFactory = retryExceptionPolicyFactory; _logger = logger; - _cosmosClients = new ConcurrentDictionary(); _lockObject = new object(); } @@ -60,24 +59,16 @@ public CosmosClient CreateCosmosClient(CosmosDataStoreConfiguration configuratio string key = string.IsNullOrEmpty(configuration.Host) ? "local" : configuration.Host; // Thread-safe logic to ensure that a single instance of CosmosClient is created per host. - if (_cosmosClients.TryGetValue(key, out CosmosClient client1)) + if (_cosmosClient != null) { - return client1; + return _cosmosClient; } else { lock (_lockObject) { - if (_cosmosClients.TryGetValue(key, out CosmosClient client2)) - { - return client2; - } - else - { - var client = CreateCosmosClientInternal(configuration); - _cosmosClients.TryAdd(key, client); - return client; - } + _cosmosClient = CreateCosmosClientInternal(configuration); + return _cosmosClient; } } }