Repository navigation
Add Blazor WebAssembly Service Defaults template #64807
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
Changes from all commits
71466a9
a9caaa6
5b8f450
ccf1709
d405c38
ffc63ff
6fad7f6
75e9745
3db4acf
33cf55f
d857ca4
18e6289
58e0222
553d0a0
7eb84d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,6 +149,9 @@ | |
| <GrpcNetClientVersion>2.64.0</GrpcNetClientVersion> | ||
| <GrpcToolsVersion>2.64.0</GrpcToolsVersion> | ||
| <MessagePackVersion>2.5.187</MessagePackVersion> | ||
| <!-- Extensions packages for Blazor WASM Service Defaults --> | ||
| <MicrosoftExtensionsHttpResilienceVersion>10.0.0</MicrosoftExtensionsHttpResilienceVersion> | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair question. For GA, the OTel packages should come from the Short-term: these manual version pins are needed while the template uses custom exporters. Once we switch to standard |
||
| <MicrosoftExtensionsServiceDiscoveryVersion>10.0.0</MicrosoftExtensionsServiceDiscoveryVersion> | ||
| <MicrosoftIdentityWebVersion>3.14.1</MicrosoftIdentityWebVersion> | ||
| <MicrosoftIdentityWebGraphServiceClientVersion>3.14.1</MicrosoftIdentityWebGraphServiceClientVersion> | ||
| <MicrosoftIdentityWebUIVersion>3.14.1</MicrosoftIdentityWebUIVersion> | ||
|
|
@@ -161,6 +164,11 @@ | |
| <NewtonsoftJsonBsonVersion>1.0.2</NewtonsoftJsonBsonVersion> | ||
| <NewtonsoftJsonVersion>13.0.3</NewtonsoftJsonVersion> | ||
| <NSwagApiDescriptionClientVersion>13.0.4</NSwagApiDescriptionClientVersion> | ||
| <!-- OpenTelemetry packages for Blazor WASM Service Defaults --> | ||
| <OpenTelemetryExporterOpenTelemetryProtocolVersion>1.10.0</OpenTelemetryExporterOpenTelemetryProtocolVersion> | ||
| <OpenTelemetryExtensionsHostingVersion>1.10.0</OpenTelemetryExtensionsHostingVersion> | ||
| <OpenTelemetryInstrumentationHttpVersion>1.10.0</OpenTelemetryInstrumentationHttpVersion> | ||
| <OpenTelemetryInstrumentationRuntimeVersion>1.10.0</OpenTelemetryInstrumentationRuntimeVersion> | ||
| <PhotinoNETVersion>2.5.2</PhotinoNETVersion> | ||
| <MicrosoftPlaywrightVersion>1.58.0</MicrosoftPlaywrightVersion> | ||
| <PollyExtensionsHttpVersion>3.0.0</PollyExtensionsHttpVersion> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Microsoft.AspNetCore.Components; | ||
|
|
||
| /// <summary> | ||
| /// Configuration that flows from the server to the Blazor client in the browser | ||
| /// via a DOM comment. Only serializable options; callbacks stay with JS initializers. | ||
| /// </summary> | ||
| public sealed class BrowserConfiguration | ||
| { | ||
| /// <summary> | ||
| /// The log level for the Blazor JS runtime. Applies to all render modes. | ||
| /// Maps to <c>WebStartOptions.logLevel</c>. | ||
| /// </summary> | ||
| public int? LogLevel { get; set; } | ||
|
|
||
| /// <summary>WebAssembly-specific options.</summary> | ||
| public WebAssemblyBrowserOptions WebAssembly { get; set; } = new(); | ||
|
|
||
| /// <summary>Server/Circuit-specific options.</summary> | ||
| public ServerBrowserOptions Server { get; set; } = new(); | ||
|
|
||
| /// <summary>SSR-specific options.</summary> | ||
| public SsrBrowserOptions Ssr { get; set; } = new(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Microsoft.AspNetCore.Components; | ||
|
|
||
| /// <summary> | ||
| /// Serializable subset of <c>CircuitStartOptions</c>. | ||
| /// Non-serializable options (<c>configureSignalR</c>, <c>reconnectionHandler</c>, | ||
| /// <c>circuitHandlers</c>) must use <c>Blazor.start()</c> or JS initializers. | ||
| /// </summary> | ||
| public sealed class ServerBrowserOptions | ||
| { | ||
| /// <summary> | ||
| /// Maximum reconnection attempts before giving up. | ||
| /// Maps to <c>CircuitStartOptions.reconnectionOptions.maxRetries</c>. | ||
| /// </summary> | ||
| public int? ReconnectionMaxRetries { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Base interval in milliseconds between reconnection attempts (scalar form). | ||
| /// The function form <c>(retryCount, currentMs) => number</c> requires JS. | ||
| /// Maps to <c>CircuitStartOptions.reconnectionOptions.retryIntervalMilliseconds</c>. | ||
| /// </summary> | ||
| public int? ReconnectionRetryIntervalMilliseconds { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// CSS ID of the reconnection dialog element. | ||
| /// Maps to <c>CircuitStartOptions.reconnectionOptions.dialogId</c>. | ||
| /// </summary> | ||
| public string? ReconnectionDialogId { get; set; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Microsoft.AspNetCore.Components; | ||
|
|
||
| /// <summary> | ||
| /// Serializable subset of <c>SsrStartOptions</c>. | ||
| /// </summary> | ||
| public sealed class SsrBrowserOptions | ||
| { | ||
| /// <summary> | ||
| /// When true, disables DOM preservation during enhanced navigation. | ||
| /// Maps to <c>SsrStartOptions.disableDomPreservation</c>. | ||
| /// </summary> | ||
| public bool? DisableDomPreservation { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Timeout in milliseconds before an inactive circuit is disposed. | ||
| /// Maps to <c>SsrStartOptions.circuitInactivityTimeoutMs</c>. | ||
| /// </summary> | ||
| public int? CircuitInactivityTimeoutMs { get; set; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Microsoft.AspNetCore.Components; | ||
|
|
||
| /// <summary> | ||
| /// Serializable subset of <c>WebAssemblyStartOptions</c>. | ||
| /// Non-serializable options (<c>loadBootResource</c>, <c>configureRuntime</c>, | ||
| /// <c>initializers</c>) must use <c>Blazor.start()</c> or JS initializers. | ||
| /// </summary> | ||
| public sealed class WebAssemblyBrowserOptions | ||
| { | ||
| /// <summary> | ||
| /// Hosting environment name (e.g., "Development", "Production"). | ||
| /// Maps to <c>WebAssemblyStartOptions.environment</c>. | ||
| /// </summary> | ||
| public string? EnvironmentName { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Application culture in BCP 47 format (e.g., "en-US"). | ||
| /// Maps to <c>WebAssemblyStartOptions.applicationCulture</c>. | ||
| /// </summary> | ||
| public string? ApplicationCulture { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Environment variables for the .NET WebAssembly runtime. | ||
| /// Use for OTEL endpoints, service URLs, etc. | ||
| /// </summary> | ||
| public Dictionary<string, string> EnvironmentVariables { get; set; } = new(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // 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; | ||
|
|
||
| namespace Microsoft.AspNetCore.Http; | ||
|
|
||
| /// <summary> | ||
| /// Extension methods on <see cref="HttpContext"/> for accessing <see cref="BrowserConfiguration"/>. | ||
| /// </summary> | ||
| public static class BrowserConfigurationHttpContextExtensions | ||
| { | ||
| private static readonly object Key = new(); | ||
|
|
||
| /// <summary> | ||
| /// Gets the <see cref="BrowserConfiguration"/> for the current request. | ||
| /// If not already set, seeds from endpoint metadata or creates a new instance. | ||
| /// </summary> | ||
| /// <param name="context">The <see cref="HttpContext"/>.</param> | ||
| /// <returns>The <see cref="BrowserConfiguration"/> for the current request.</returns> | ||
| public static BrowserConfiguration GetBrowserConfiguration(this HttpContext context) | ||
| { | ||
| if (!context.Items.TryGetValue(Key, out var result)) | ||
| { | ||
| // Seed from endpoint metadata if available | ||
| var metadataConfig = context.GetEndpoint()?.Metadata.GetMetadata<BrowserConfiguration>(); | ||
| var config = metadataConfig ?? new BrowserConfiguration(); | ||
| context.Items[Key] = config; | ||
| return config; | ||
| } | ||
|
|
||
| return (BrowserConfiguration)result!; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // 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.Http; | ||
|
|
||
| namespace Microsoft.AspNetCore.Components; | ||
|
|
||
| /// <summary> | ||
| /// A component that configures the Blazor browser runtime by merging | ||
| /// configuration into the <see cref="BrowserConfiguration"/> on the current | ||
| /// <see cref="HttpContext"/>. The merged configuration is emitted as | ||
| /// a <c><!--Blazor-Configuration:{...}--></c> DOM comment by the renderer. | ||
| /// </summary> | ||
| public sealed class ConfigureBrowser : IComponent | ||
| { | ||
| private RenderHandle _renderHandle; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the <see cref="BrowserConfiguration"/> to merge. | ||
| /// </summary> | ||
| [Parameter, EditorRequired] | ||
| public BrowserConfiguration Configuration { get; set; } = default!; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the <see cref="HttpContext"/> for the current request. | ||
| /// </summary> | ||
| [CascadingParameter] | ||
| public HttpContext? HttpContext { get; set; } | ||
|
|
||
| void IComponent.Attach(RenderHandle renderHandle) | ||
| { | ||
| _renderHandle = renderHandle; | ||
| } | ||
|
|
||
| Task IComponent.SetParametersAsync(ParameterView parameters) | ||
| { | ||
| parameters.SetParameterProperties(this); | ||
|
|
||
| if (HttpContext is not null) | ||
| { | ||
| var existing = HttpContext.GetBrowserConfiguration(); | ||
| MergeInto(existing, Configuration); | ||
| } | ||
|
|
||
| return Task.CompletedTask; | ||
| } | ||
|
|
||
| internal static void MergeInto(BrowserConfiguration target, BrowserConfiguration source) | ||
| { | ||
| target.LogLevel = source.LogLevel ?? target.LogLevel; | ||
|
|
||
| // WebAssembly | ||
| target.WebAssembly.EnvironmentName = source.WebAssembly.EnvironmentName ?? target.WebAssembly.EnvironmentName; | ||
| target.WebAssembly.ApplicationCulture = source.WebAssembly.ApplicationCulture ?? target.WebAssembly.ApplicationCulture; | ||
| foreach (var kvp in source.WebAssembly.EnvironmentVariables) | ||
| { | ||
| target.WebAssembly.EnvironmentVariables[kvp.Key] = kvp.Value; | ||
| } | ||
|
|
||
| // Server | ||
| target.Server.ReconnectionMaxRetries = source.Server.ReconnectionMaxRetries ?? target.Server.ReconnectionMaxRetries; | ||
| target.Server.ReconnectionRetryIntervalMilliseconds = source.Server.ReconnectionRetryIntervalMilliseconds ?? target.Server.ReconnectionRetryIntervalMilliseconds; | ||
| target.Server.ReconnectionDialogId = source.Server.ReconnectionDialogId ?? target.Server.ReconnectionDialogId; | ||
|
|
||
| // SSR | ||
| target.Ssr.DisableDomPreservation = source.Ssr.DisableDomPreservation ?? target.Ssr.DisableDomPreservation; | ||
| target.Ssr.CircuitInactivityTimeoutMs = source.Ssr.CircuitInactivityTimeoutMs ?? target.Ssr.CircuitInactivityTimeoutMs; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,7 +72,6 @@ public static IRazorComponentsBuilder AddRazorComponents(this IServiceCollection | |
| services.AddSupplyValueFromQueryProvider(); | ||
| services.AddSupplyValueFromPersistentComponentStateProvider(); | ||
| services.TryAddCascadingValue(sp => sp.GetRequiredService<EndpointHtmlRenderer>().HttpContext); | ||
| services.TryAddScoped<WebAssemblySettingsEmitter>(); | ||
| services.TryAddScoped<ResourcePreloadService>(); | ||
| services.AddTempData(); | ||
|
Comment on lines
72
to
76
|
||
|
|
||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Microsoft.AspNetCore.Components; | ||
|
|
||
| [JsonSourceGenerationOptions( | ||
| PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, | ||
| DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] | ||
| [JsonSerializable(typeof(BrowserConfiguration))] | ||
| internal partial class BrowserConfigurationJsonContext : JsonSerializerContext | ||
| { | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the plan for keeping these updated? We already have a subscription from dotnet/extensions that currently gives us the 10.4.x versions of packages (see
aspnetcore/eng/Version.Details.props
Lines 101 to 104 in 99e8596