Skip to content

API Proposal: ServerComponentsEndpointOptions.ConfigureConnection #66387

@javiercn

Description

@javiercn

Background and Motivation

Users of AddInteractiveServerRenderMode had no clean way to configure the underlying SignalR HttpConnectionDispatcherOptions. Previously, users had to resort to workarounds using metadata inspection to access properties like CloseOnAuthenticationExpiration. The old MapBlazorHub had overloads accepting dispatcher options, but AddInteractiveServerRenderMode did not expose this configuration surface.

Source: PR #63825, fixes #63520.

Proposed API

namespace Microsoft.AspNetCore.Components.Server;

public class ServerComponentsEndpointOptions
{
+    public Action<HttpConnectionDispatcherOptions>? ConfigureConnection { get; set; }
}

Usage Examples

app.MapRazorComponents<App>()
    .AddInteractiveServerRenderMode(options =>
    {
        options.ConfigureConnection = dispatcherOptions =>
        {
            dispatcherOptions.CloseOnAuthenticationExpiration = true;
            dispatcherOptions.AllowStatefulReconnects = true;
            dispatcherOptions.ApplicationMaxBufferSize = 1024 * 1024;
        };
    });

Alternative Designs

The workaround was inspecting metadata via .Add(e => { var opts = e.Metadata.OfType<HttpConnectionDispatcherOptions>().FirstOrDefault(); ... }). This was not type-safe, hard to discover, fragile, and inconsistent with MapBlazorHub.

Risks

None — additive property, null by default preserves existing behavior. Zero overhead when not used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedAPI was approved in API review, it can be implementedapi-proposalarea-blazorIncludes: Blazor, Razor Components

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions