Skip to content

.NET: Switch auth sample to use Singletons - #4454

Merged
westey (westey-m) merged 5 commits into
microsoft:mainfrom
westey-m:auth-sample-singlton
Mar 5, 2026
Merged

.NET: Switch auth sample to use Singletons#4454
westey (westey-m) merged 5 commits into
microsoft:mainfrom
westey-m:auth-sample-singlton

Conversation

@westey-m

Copy link
Copy Markdown
Contributor

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.

CopilotAI review requested due to automatic review settings March 4, 2026 12:29
@markwallace-microsoftMark Wallace (markwallace-microsoft) added the .NET Usage: [Issues, PRs], Target: .Net label Mar 4, 2026
@github-actionsgithub-actionsBot changed the title Switch auth sample to use Singletons.NET: Switch auth sample to use SingletonsMar 4, 2026

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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.

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

@westey-m
westey (westey-m) added this pull request to the merge queueMar 5, 2026
@github-merge-queue
github-merge-queueBot removed this pull request from the merge queue due to failed status checks Mar 5, 2026
@westey-m
westey (westey-m) added this pull request to the merge queueMar 5, 2026
Merged via the queue into microsoft:main with commit 4a043c6Mar 5, 2026
21 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NETUsage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@westey-m@rogerbarreto@SergeyMenshykh@markwallace-microsoft