dotnet / dotnet/efcore

No longer possible to initialize CosmosDB client

Open
#28,018 3 comments 2 reactions 0 assignees View on GitHub
area-cosmos customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

## File a bug
In Microsoft.Azure.Cosmos v3.27.0 to initialize cosmosdb the only way is now to call CosmosClient.CreateAndInitializeAsync();
With CosmosSDK 2.0 it was possible to call OpenAsync to avoid startup latency on first request Ex:
```C#
await context.DataBase.GetCosmosclient().OpenAsync();
```
But this method have been removed and it's no possible anymore to Initialize CosmosDB client after it have been created.
The problem we are having with Entity Framework Core is that Entity Framework is creating the CosmosClient instance at

https://github.com/dotnet/efcore/blob/70cd92974e09e938a92384e91b5c3179f4773725/src/EFCore.Cosmos/Storage/Internal/SingletonCosmosClientWrapper.cs#L103

And is not calling CreateAndInitializeAsync()

This is causing first request to take 2 seconds instead of 20 ms

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.