Skip to content

feat(Middleware): add AddBootstraBlazorHub extension method - #1253

Merged
ArgoZhang merged 3 commits into
masterfrom
feat-middle
Oct 27, 2026
Merged

ArgoZhang merged 3 commits into
masterfrom
feat-middle

Conversation

@ArgoZhang

@ArgoZhang ArgoZhang commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Link issues

fixes #1251

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Add a shared, configurable SignalR hub for BootstrapBlazor messaging and online connection management.

New Features:

  • Add configurable SignalR hub registration and endpoint mapping for BootstrapBlazor server applications.
  • Support opt-in message subscriptions, client publishing, server-side dispatch, heartbeats, and connection snapshots through the shared hub.

Enhancements:

  • Extract the client IP lookup endpoint handling into a dedicated request handler while preserving the existing middleware behavior.
  • Add bilingual API documentation for the middleware and hub functionality.

@bb-auto bb-auto Bot added the enhancement New feature or request label Oct 27, 2026
@sourcery-ai

sourcery-ai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Introduces a shared BootstrapBlazor SignalR hub with explicit configuration for dispatch types, client publishing, heartbeats, and connection snapshots; wires it into DI and endpoint routing while refactoring the existing IP lookup middleware into a dedicated handler.

Sequence diagram for SignalR message subscription and dispatch

sequenceDiagram
    actor Client
    participant Hub as BootstrapBlazorHub
    participant Handler as DispatchHandler
    participant Service as DefaultDispatchService
    participant Subscribers as SignalR subscribers

    Client->>Hub: Subscribe(entryType)
    Hub->>Handler: SubscribeAsync(context, groups, entryType, options)
    Handler-->>Client: true or false
    Client->>Hub: Dispatch(entryType, entry)
    Hub->>Handler: DispatchAsync(context, entryType, entry, options, services)
    Handler->>Service: DispatchAsync(entry, connectionId)
    Service->>Subscribers: Receive(entryType, entry)
Loading

Sequence diagram for connection heartbeat and snapshot query

sequenceDiagram
    actor Client
    participant Hub as BootstrapBlazorHub
    participant Handler as ConnectionHandler
    participant ConnectionService as IConnectionService
    participant Authorization as IAuthorizationService

    Client->>Hub: Heartbeat(client)
    Hub->>Handler: ReportHeartbeatAsync(context, client, services)
    Handler->>ConnectionService: AddOrUpdateAsync(client)
    ConnectionService-->>Handler: completed
    Handler-->>Client: true
    Client->>Hub: GetConnectionSnapshot()
    Hub->>Handler: GetSnapshotAsync(context, options, services)
    opt ConnectionSnapshotAuthorizationPolicy configured
        Handler->>Authorization: AuthorizeAsync(user, policy)
    end
    Handler-->>Client: ConnectionSnapshot or null
Loading

File-Level Changes

Change Details Files
Adds a shared, configurable SignalR hub for client subscriptions, server/client message dispatch, application heartbeats, and optional connection snapshots.
  • Introduces hub methods for subscribe, unsubscribe, dispatch, heartbeat, and snapshot retrieval.
  • Adds opt-in entry-type registration with optional client publishing and payload deserialization.
  • Implements group-based SignalR delivery, local subscriber callbacks, cancellation, and callback error isolation.
  • Adds heartbeat validation, IP/user enrichment, connection persistence, and optional authorization for snapshots.
src/middleware/BootstrapBlazor.Middleware/BootstrapBlazorHub.cs
src/middleware/BootstrapBlazor.Middleware/BootstrapBlazorHubOptions.cs
src/middleware/BootstrapBlazor.Middleware/ConnectionHandler.cs
src/middleware/BootstrapBlazor.Middleware/DefaultDispatchService.cs
src/middleware/BootstrapBlazor.Middleware/DispatchHandler.cs
Exposes dependency-injection registration and endpoint-mapping APIs for the new hub.
  • Adds AddBootstrapBlazorHub configuration and registers SignalR plus the default generic dispatch service.
  • Adds MapBootstrapBlazorHub with a configurable endpoint pattern and support for endpoint authorization conventions.
src/middleware/BootstrapBlazor.Middleware/ServiceCollectionExtensions.cs
src/middleware/BootstrapBlazor.Middleware/BootstrapBlazor.Middleware.csproj
Preserves the existing client-IP endpoint while extracting its request handling and improving middleware documentation.
  • Moves /ip.axd response generation into a dedicated handler without changing its forwarded-IP behavior.
  • Replaces conditional middleware branching with MapWhen and the extracted handler.
  • Adds bilingual XML documentation and updates internal IP conversion documentation.
src/middleware/BootstrapBlazor.Middleware/BootstrapBlazorApplicationBuilderExtensions.cs
src/middleware/BootstrapBlazor.Middleware/IpRequestHandler.cs
src/middleware/BootstrapBlazor.Middleware/InternalIPAddressExtensions.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#1251 Provide an extension method to register BootstrapBlazor's SignalR Hub services. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto Bot added this to the v10.0.0 milestone Oct 27, 2026
bb-auto[bot]
bb-auto Bot previously approved these changes Oct 27, 2026

@bb-auto bb-auto Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Auto approved by bb-auto

@bb-auto bb-auto Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Auto approved by bb-auto

@ArgoZhang
ArgoZhang merged commit 0e4e228 into master Oct 27, 2026
3 checks passed
@ArgoZhang
ArgoZhang deleted the feat-middle branch October 27, 2026 00:46

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(Middleware): add AddBootstraBlazorHub extension method

1 participant