Skip to content

Conversation

@JoasE
Copy link
Contributor

@JoasE JoasE commented Oct 24, 2025

Allows the user to retrieve session tokens from reads and writes done by a dbcontext and set session tokens to use for reads.
Adds a GetSessionTokens() extension method to DatabaseFacade which returns session tokens per container.
Adds UseSessionTokens() and AppendSessionTokens() extension methods to DatabaseFacade which allow setting and appending session tokens per container.
Adds GetSessionToken() and Use/AppendSessionToken() for the default container.
Adds option SessionTokenManagementMode to CosmosDbContextOptionsBuilder

Add 4 SessionTokenManagementMode's:

  • FullyAutomatic (default) - Just the automatic token management in CosmosClient. GetSessionTokens and UseSessionTokens throw when invoked.
  • SemiAutomatic - Session tokens are sent with a request if UseSessionTokens was called for that container. Otherwise automatic token management will be used
  • Manual - Only tokens specified via UseSessionTokens or tracked by requests done by EF in a DbContext are used.
  • EnforcedManual - Same as Manual but throws if UseSessionTokens wasn't called before a request for a specific container.

Implements: #36504

  • I've read the guidelines for contributing and seen the walkthrough
  • I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • The code builds and tests pass locally (also verified by our automated build checks)
  • Commit messages follow this format:
        Summary of the changes
        - Detail 1
        - Detail 2

        Fixes #bugnumber
  • Tests for the changes have been added (for bug fixes / features)
  • Code follows the same patterns and style as existing code in this repo

@JoasE JoasE changed the title Add Cosmos db manual session token management #36504 Add Cosmos db manual session token management Oct 24, 2025
Copy link
Contributor Author

@JoasE JoasE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions from me still

@JoasE JoasE marked this pull request as ready for review November 1, 2025 16:45
@JoasE JoasE requested a review from a team as a code owner November 1, 2025 16:45
@JoasE JoasE marked this pull request as draft November 5, 2025 10:15
@JoasE JoasE marked this pull request as ready for review November 10, 2025 20:15
@JoasE JoasE requested a review from AndriySvyryd November 12, 2025 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants