Skip to content

.NET: Switch auth sample to use Singletons#4454

Open
westey-m wants to merge 4 commits intomicrosoft:mainfrom
westey-m:auth-sample-singlton
Open

.NET: Switch auth sample to use Singletons#4454
westey-m wants to merge 4 commits intomicrosoft:mainfrom
westey-m:auth-sample-singlton

Conversation

@westey-m
Copy link
Contributor

@westey-m westey-m commented Mar 4, 2026

Motivation and Context

#4446

Description

  • Switch auth sample to use Singletons

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings March 4, 2026 12:29
@github-actions github-actions bot changed the title Switch auth sample to use Singletons .NET: Switch auth sample to use Singletons Mar 4, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the AspNetAgentAuthorization end-to-end .NET sample to register the agent and its supporting services as singletons, aligning the sample with the recommended singleton-style registration pattern discussed in #4446.

Changes:

  • Convert KeycloakUserContext to be singleton-safe by reading claims from the current HttpContext on-demand.
  • Change DI registrations for IUserContext, ExpenseService, and AIAgent from scoped to singleton in the sample Program.cs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
dotnet/samples/05-end-to-end/AspNetAgentAuthorization/Service/UserContext.cs Refactors user context to be singleton-friendly by resolving user info from HttpContext per property access.
dotnet/samples/05-end-to-end/AspNetAgentAuthorization/Service/Program.cs Switches sample DI registrations to singletons for user context, expense service, and the agent.

@westey-m westey-m added this pull request to the merge queue Mar 5, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants