Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cosmos : Need an option to inject/reuse external CosmosClient during the setup of EF Core Azure Cosmos DB Provider #26863

Closed
surenderssm opened this issue Dec 1, 2021 · 3 comments

Comments

@surenderssm
Copy link

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.

As per the recommendation for better performance, we should strive for single instance of CosmosClient per AppDomain.
https://docs.microsoft.com/en-us/azure/cosmos-db/sql/performance-tips-dotnet-sdk-v3-sql

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.

@ajcvickers
Copy link
Contributor

/cc @AndriySvyryd

@AndriySvyryd
Copy link
Member

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
Copy link
Author

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.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants