-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Make Razor Components apps not use Blazor build #6562
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
9a13ef2
f9350f4
ebdb966
1599a65
0c012ef
5f11311
30dfd71
c8763c3
479d293
39a6291
1d9ccce
80ac9fc
9b650ac
b82d3a1
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<!-- | ||
Configuring this stuff here is temporary. Later we'll move the app config | ||
into Program.cs, and it won't be necessary to specify AppAssembly. | ||
into Startup.cs, and it won't be necessary to specify AppAssembly. | ||
--> | ||
<Router AppAssembly=typeof(ComponentsApp.App.Program).Assembly /> | ||
<Router AppAssembly=typeof(ComponentsApp.App.Startup).Assembly /> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
<Project Sdk="Microsoft.NET.Sdk.Razor"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(AspNetCorePackageVersion)" /> | ||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Components\Microsoft.AspNetCore.Components.csproj" /> | ||
</ItemGroup> | ||
<!-- Local equivalent to a package reference to Microsoft.AspNetCore.Components.Build --> | ||
<Import Project="..\..\src\Microsoft.AspNetCore.Components.Build\ReferenceFromSource.props" /> | ||
|
||
<!-- Local alternative to <PackageReference Include="Microsoft.AspNetCore.Blazor.Build" /> --> | ||
<Import Project="..\..\blazor\src\Microsoft.AspNetCore.Blazor.Build\ReferenceFromSource.props" /> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(AspNetCorePackageVersion)" /> | ||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Components\Microsoft.AspNetCore.Components.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<!-- Allow the build to specify the version of the Razor SDK directly --> | ||
<PackageReference Include="Microsoft.NET.Sdk.Razor" Version="$(MicrosoftNETSdkRazorPackageVersion)" PrivateAssets="All" /> | ||
</ItemGroup> | ||
</Project> | ||
|
||
</Project> | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using Microsoft.AspNetCore.Components.Server; | ||
using Microsoft.AspNetCore.Components.Server.Builder; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.FileProviders; | ||
|
||
namespace Microsoft.AspNetCore.Builder | ||
{ | ||
/// <summary> | ||
/// Extension methods to configure an <see cref="IApplicationBuilder"/> for serving interactive components. | ||
/// </summary> | ||
public static class RazorComponentsApplicationBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Adds middleware for serving interactive Razor Components. | ||
/// </summary> | ||
/// <param name="builder">The <see cref="IApplicationBuilder"/>.</param> | ||
/// <typeparam name="TStartup">A components app startup type.</typeparam> | ||
/// <returns>The <see cref="IApplicationBuilder"/>.</returns> | ||
public static IApplicationBuilder UseRazorComponents<TStartup>( | ||
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. Technically we don't need the I'm totally open to changing this though. 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. Good to know. I think we should leave it as-is until we resolve all of the dependencies and tweaks needed to ship preview2. |
||
this IApplicationBuilder builder) | ||
{ | ||
return UseRazorComponents<TStartup>(builder, null); | ||
} | ||
|
||
/// <summary> | ||
/// Adds middleware for serving interactive Razor Components. | ||
/// </summary> | ||
/// <param name="builder">The <see cref="IApplicationBuilder"/>.</param> | ||
/// <param name="configure">A callback that can be used to configure the middleware.</param> | ||
/// <typeparam name="TStartup">A components app startup type.</typeparam> | ||
/// <returns>The <see cref="IApplicationBuilder"/>.</returns> | ||
public static IApplicationBuilder UseRazorComponents<TStartup>( | ||
this IApplicationBuilder builder, | ||
Action<RazorComponentsOptions> configure) | ||
{ | ||
if (builder == null) | ||
{ | ||
throw new ArgumentNullException(nameof(builder)); | ||
} | ||
|
||
var options = new RazorComponentsOptions(); | ||
configure?.Invoke(options); | ||
|
||
// The use case for this flag is when developers want to add their own | ||
// SignalR middleware, e.g., when using Azure SignalR. By default we | ||
// add SignalR and BlazorHub automatically. | ||
if (options.UseSignalRWithBlazorHub) | ||
{ | ||
builder.UseSignalR(route => route.MapHub<BlazorHub>(BlazorHub.DefaultPath)); | ||
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. does this need to be renamed to components? 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. Yeah, eventually. There are lots of remaining bits of renaming-cleanup like that, but I'm not trying to get all of them done before Preview 2. I'm only focused on the ones that are really in developers' faces in default scenarios, which this isn't. |
||
} | ||
|
||
// Use embedded static content for /_framework | ||
builder.Map("/_framework", frameworkBuilder => | ||
{ | ||
UseFrameworkFiles(frameworkBuilder); | ||
}); | ||
|
||
// Use SPA fallback routing for anything else | ||
builder.UseSpa(spa => { }); | ||
|
||
return builder; | ||
} | ||
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. This got me thinking. The core of this method would be I'm wondering what your thoughts are on having something like this directly on the template. builder.UseSignalR(r => r.MapComponentsHub()); compared to The reason for it being that it's more straightforward what's going on in the pipeline and its easier to manipulate, for example to add Azure SignalR (it composes better). Thoughts? 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.
Yep, we would need to do that. I'd be keen not to have The mechanism here of serving it from middleware in 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.
Also servicing. |
||
|
||
private static void UseFrameworkFiles(IApplicationBuilder builder) | ||
{ | ||
builder.UseStaticFiles(new StaticFileOptions | ||
{ | ||
FileProvider = new ManifestEmbeddedFileProvider( | ||
typeof(RazorComponentsApplicationBuilderExtensions).Assembly, | ||
"frameworkFiles"), | ||
OnPrepareResponse = BlazorApplicationBuilderExtensions.SetCacheHeaders | ||
}); | ||
|
||
// TODO: Remove this | ||
// This is needed temporarily only until we implement a proper version | ||
// of library-embedded static resources for Razor Components apps. | ||
builder.Map("/blazor.boot.json", bootJsonBuilder => | ||
{ | ||
bootJsonBuilder.Use(async (ctx, next) => | ||
{ | ||
ctx.Response.ContentType = "application/json"; | ||
await ctx.Response.WriteAsync(@"{ ""cssReferences"": [], ""jsReferences"": [] }"); | ||
}); | ||
}); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.AspNetCore.Builder; | ||
|
||
namespace Microsoft.AspNetCore.Components.Server.Builder | ||
{ | ||
/// <summary> | ||
/// Specifies options to configure <see cref="RazorComponentsApplicationBuilderExtensions.UseRazorComponents{TStartup}(IApplicationBuilder)"/> | ||
/// </summary> | ||
public class RazorComponentsOptions | ||
{ | ||
/// <summary> | ||
/// Gets or sets a flag to indicate whether to attach middleware for | ||
/// communicating with interactive components via SignalR. Defaults | ||
/// to true. | ||
/// | ||
/// If the value is set to false, the application must manually add | ||
/// SignalR middleware with <see cref="BlazorHub"/>. | ||
/// </summary> | ||
public bool UseSignalRWithBlazorHub { get; set; } = true; | ||
} | ||
} |
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.
❤️