Skip to content

Consent Index: Refactor to MediatR commands/queries#1376

Merged
StuartFerguson merged 2 commits intomasterfrom
copilot/refactor-consent-index-class
Apr 12, 2026
Merged

Consent Index: Refactor to MediatR commands/queries#1376
StuartFerguson merged 2 commits intomasterfrom
copilot/refactor-consent-index-class

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 12, 2026

The Consent/Index Razor Page had SecurityServiceDbContext and IOpenIddictApplicationManager injected directly into its constructor. This refactors it to use the MediatR pattern already established across the rest of the codebase.

Changes

  • OidcCommands.cs — Added ConsentGetQuery(HttpContext, ReturnUrl) and ConsentPostCommand(ReturnUrl, Button, SelectedScopes)
  • OidcResults.cs — Added result types: ConsentGetPageResult, ConsentGetLocalRedirectResult, ConsentPostRedirectResult, ConsentPostPageResult
  • ConsentRequestHandler.cs (new) — Handles both commands; holds the infrastructure dependencies (IOpenIddictApplicationManager, SecurityServiceDbContext)
  • Consent/Index.cshtml.cs — Reduced to a single IMediator constructor dependency; all logic delegated via mediator.Send()
  • Tests — Added ConsentRequestHandlerTests and ConsentPageModelTests following the same patterns as VerifyRequestHandlerTests / VerifyPageModelTests

Before / After

// Before
public IndexModel(SecurityServiceDbContext dbContext, IOpenIddictApplicationManager applicationManager) { ... }

// After
public IndexModel(IMediator mediator) { ... }

public async Task<IActionResult> OnGetAsync(string returnUrl, CancellationToken cancellationToken)
{
    var result = await this._mediator.Send(new OidcCommands.ConsentGetQuery(this.HttpContext, returnUrl), cancellationToken);
    return result.Data switch
    {
        ConsentGetLocalRedirectResult redirect => this.LocalRedirect(redirect.Url),
        ConsentGetPageResult page => this.ApplyPageResult(page),
        _ => this.Page()
    };
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • f.feedz.io
    • Triggering command: /usr/bin/dotnet dotnet build SecurityService.slnx --configuration Release (dns block)
    • Triggering command: /usr/bin/dotnet dotnet build SecurityService.BusinessLogic/SecurityService.BusinessLogic.csproj --configuration Release (dns block)
    • Triggering command: /usr/bin/dotnet dotnet build SecurityService.UnitTests/SecurityService.UnitTests.csproj --configuration Release (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI linked an issue Apr 12, 2026 that may be closed by this pull request
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Apr 12, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 8 complexity · 0 duplication

Metric Results
Complexity 8
Duplication 0

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

Copilot AI changed the title [WIP] Refactor Consent Index to use commands/queries and Mediatr pattern Consent Index: Refactor to MediatR commands/queries Apr 12, 2026
Copilot AI requested a review from StuartFerguson April 12, 2026 17:40
@StuartFerguson StuartFerguson marked this pull request as ready for review April 12, 2026 17:42
@StuartFerguson StuartFerguson merged commit c450e2c into master Apr 12, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consent Index Refactor

2 participants