Skip to content

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

Closed as not planned

Description

@surenderssm

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.

Activity

  1. ajcvickers commented on Dec 3, 2021

    @ajcvickers
    Contributor
  2. AndriySvyryd commented on Dec 6, 2021

    @AndriySvyryd
    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.

  3. surenderssm commented on Dec 7, 2021

    @surenderssm
    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions