Skip to content

Use different serializer settings with the same client instance #3341

Open

Description

Is your feature request related to a problem? Please describe.
Currently specifying a custom serializer (or serialization settings) is only possible at the CosmosClient level.
However, we have many scenarios where we need to use different serialization settings for each request.
It's highly encouraged to use single instance clients:

Its recommended to maintain a single instance of CosmosClient per lifetime of the application which enables efficient connection management and performance

Each DocumentClient instance is thread-safe and performs efficient connection management and address caching when operating in direct mode. To allow efficient connection management and better SDK client performance, we recommend that you use a single instance per AppDomain for the lifetime of the application.

While it is possible to use Stream based APIs for some usages to circumvent this limitation, it is not possible to use with LINQ (GetItemLinqQueryable) which is our primary API.

Describe the solution you'd like
Allow changing the custom serializer / settings after the client is created. Either of these would work well for our scenarios:

  • CosmosClient.WithSerializer(CosmosSerializer, CosmosSerializerOptions) - returns a new instance of the client that utilizes the same connection but with a different serializer
  • CosmosClient.GetContainer(CosmosSerializer, CosmosSerializerOptions) - same as above, but at the container level

Describe alternatives you've considered
Use multiple CosmosClient instances.

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

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status

      Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions