You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cosmos : Need an option to inject/reuse external CosmosClient during the setup of EF Core Azure Cosmos DB Provider #26863
Currently Azure Cosmos DB .NET SDK v3 for SQL API Microsoft.Azure.Cosmos is the recommended and preferred SDK to interact with Cosmos DB.
In some scenarios depending on the use case and to leverage benefits of EF Core (like odata support in our case), one also uses EF Core Azure Cosmos DB Provider (Microsoft.EntityFrameworkCore.Cosmos).
In such scenarios when a consumer is using both the SDKs to interact with cosmos DB, one ends up having two CosmosClient instances per AppDomain. This seems like an overhead and not optimal usage of resources ( Connection management/Serializers) leading to double footprint of memory and network.
How about we provide an option to reuse/inject CosmosClient during the initialization of the EF Core assets or leverage DI in appropriate layer to get any already registered instance of CosmosClient.
Activity
ajcvickers commentedon Dec 3, 2021
/cc @AndriySvyryd
AndriySvyryd commentedon Dec 6, 2021
You can get the instance used by EF:
var client = context.Database.GetCosmosClient();However due to how internal EF service caching works you cannot provide an instance for EF to use.
surenderssm commentedon Dec 7, 2021
Thank you @AndriySvyryd for the update.
It would be have been super clean if there was an way to provide CosmosClient to EF to re-use.
Being optimistic hopefully down the line we might see some light on this.