Skip to content

[Blazor] Support configuring hub options #49712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
namespace Microsoft.AspNetCore.Components.Endpoints;

/// <summary>
///
/// A builder that can be used to configure Razor Components.
/// </summary>
public interface IRazorComponentsBuilder
{
/// <summary>
///
/// Gets the <see cref="IServiceCollection"/>.
/// </summary>
public IServiceCollection Services { get; }
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.AspNetCore.Components.Endpoints;

namespace Microsoft.Extensions.DependencyInjection;

/// <summary>
/// A builder that can be used to configure Server-Side Blazor.
/// </summary>
public interface IServerSideBlazorBuilder
public interface IServerSideBlazorBuilder : IRazorComponentsBuilder
{
/// <summary>
/// Gets the <see cref="IServiceCollection"/>.
/// </summary>
IServiceCollection Services { get; }
public new IServiceCollection Services { get; }
Copy link
Member

Choose a reason for hiding this comment

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

How come this is being made public here and there's an explicit interface implementation below? Wouldn't just one of those be sufficient?

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps this is to avoid a binary breaking change. I see the base interface has a default implementation of Services. AFAIK it would be source-compatible just to add the base interface and remove the property from IServerSideBlazorBuilder entirely, but perhaps that's binary-breaking.

Is that the reason or am I missing some point?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is an interface, it was already public.

I had to apply new because by making IServerSideBlazorBuilder extend IRazorComponentBuilder it was hiding the member. If I removed the ServiceCollection from here, it was a breaking change. We can take the breaking change if we want to, but that would impact any library that compiled against IBlazorServerBuilder so it just felt safer to do it this way.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is that the reason or am I missing some point?

We were both typing at the same time. Yes, its to avoid the binary breaking change.


IServiceCollection IRazorComponentsBuilder.Services => Services;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,24 @@ public static class RazorComponentsBuilderExtensions
/// <param name="configure">A callback to configure <see cref="CircuitOptions"/>.</param>
/// <returns>An <see cref="IRazorComponentsBuilder"/> that can be used to further customize the configuration.</returns>
[RequiresUnreferencedCode("Server-side Blazor does not currently support native AOT.", Url = "https://aka.ms/aspnet/nativeaot")]
public static IRazorComponentsBuilder AddServerComponents(this IRazorComponentsBuilder builder, Action<CircuitOptions>? configure = null)
public static IServerSideBlazorBuilder AddServerComponents(this IRazorComponentsBuilder builder, Action<CircuitOptions>? configure = null)
{
ArgumentNullException.ThrowIfNull(builder, nameof(builder));

builder.Services.AddServerSideBlazor(configure);
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<RenderModeEndpointProvider, CircuitEndpointProvider>());

return builder;
return new DefaultServerSideBlazorBuilder(builder.Services);
}

private sealed class DefaultServerSideBlazorBuilder : IServerSideBlazorBuilder
{
public DefaultServerSideBlazorBuilder(IServiceCollection services)
{
Services = services;
}

public IServiceCollection Services { get; }
}

private class CircuitEndpointProvider : RenderModeEndpointProvider
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Server/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
Microsoft.AspNetCore.Components.Server.Circuits.CircuitInboundActivityContext
Microsoft.AspNetCore.Components.Server.Circuits.CircuitInboundActivityContext.Circuit.get -> Microsoft.AspNetCore.Components.Server.Circuits.Circuit!
Microsoft.Extensions.DependencyInjection.RazorComponentsBuilderExtensions
static Microsoft.Extensions.DependencyInjection.RazorComponentsBuilderExtensions.AddServerComponents(this Microsoft.AspNetCore.Components.Endpoints.IRazorComponentsBuilder! builder, System.Action<Microsoft.AspNetCore.Components.Server.CircuitOptions!>? configure = null) -> Microsoft.AspNetCore.Components.Endpoints.IRazorComponentsBuilder!
static Microsoft.Extensions.DependencyInjection.RazorComponentsBuilderExtensions.AddServerComponents(this Microsoft.AspNetCore.Components.Endpoints.IRazorComponentsBuilder! builder, System.Action<Microsoft.AspNetCore.Components.Server.CircuitOptions!>? configure = null) -> Microsoft.Extensions.DependencyInjection.IServerSideBlazorBuilder!
virtual Microsoft.AspNetCore.Components.Server.Circuits.CircuitHandler.CreateInboundActivityHandler(System.Func<Microsoft.AspNetCore.Components.Server.Circuits.CircuitInboundActivityContext!, System.Threading.Tasks.Task!>! next) -> System.Func<Microsoft.AspNetCore.Components.Server.Circuits.CircuitInboundActivityContext!, System.Threading.Tasks.Task!>!