Make Razor Components apps not use Blazor build (#6562)
* Replace UseServerSideBlazor with UseRazorComponents, which doesn't require Blazor build artifacts * Make UseRazorComponents serve blazor.server.js from embedded resource ... so we don't need a build step to put it on disk somewhere. * Fix TestServer * Update ComponentsApp not to use Blazor build targets * Update ComponentsApp.App sample to use new build package * Update string constant in test * Rename blazor.*.js to components.*.js * Ensure correct build order * Update nav menu title in Components sample app * Fix remaining paths * Switch ComponentsApp.App to use Sdk="Microsoft.NET.Sdk.Razor" * Update mono.cecil version * CR: Replace FrameworkFilesProvider with EmbeddedFileProvider * CR: Use ManifestEmbeddedFileProvider
This commit is contained in:
parent
3cd5054eb5
commit
70cdf11f76
|
|
@ -19,6 +19,6 @@
|
|||
</script>
|
||||
|
||||
<app>Loading...</app>
|
||||
<script src="_framework/blazor.webassembly.js"></script>
|
||||
<script src="_framework/components.webassembly.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -7,6 +7,6 @@
|
|||
<body>
|
||||
<app>Loading...</app>
|
||||
<script src="customJsFileForTests.js"></script>
|
||||
<script src="_framework/blazor.webassembly.js"></script>
|
||||
<script src="_framework/components.webassembly.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,6 @@
|
|||
<body>
|
||||
<app>Loading...</app>
|
||||
|
||||
<script src="_framework/blazor.webassembly.js"></script>
|
||||
<script src="_framework/components.webassembly.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@
|
|||
<ExcludePackageFileFromSigning Include="System.Text.Encoding.CodePages.dll" />
|
||||
|
||||
<!-- JS files -->
|
||||
<ExcludePackageFileFromSigning Include="blazor.server.js" />
|
||||
<ExcludePackageFileFromSigning Include="blazor.webassembly.js" />
|
||||
<ExcludePackageFileFromSigning Include="components.server.js" />
|
||||
<ExcludePackageFileFromSigning Include="components.webassembly.js" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Executes /t:Publish for all target frameworks before packing-->
|
||||
|
|
@ -72,7 +72,7 @@
|
|||
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.FileProviders.Composite" Version="$(AspNetCorePackageVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="$(AspNetCorePackageVersion)" />
|
||||
<PackageReference Include="Mono.Cecil" Version="0.10.0-beta7" />
|
||||
<PackageReference Include="Mono.Cecil" Version="$(MonoCecilPackageVersion)" />
|
||||
<PackageReference Include="System.CodeDom" Version="4.4.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -22,6 +22,6 @@
|
|||
<file src="build\**" target="build" />
|
||||
<file src="targets\**" target="targets" />
|
||||
<file src="$publishdir$netcoreapp3.0\**\*" target="tools/" />
|
||||
<file src="..\..\..\src\Microsoft.AspNetCore.Components.Browser.JS\dist\blazor.*.js" target="tools/blazor" />
|
||||
<file src="..\..\..\src\Microsoft.AspNetCore.Components.Browser.JS\dist\components.*.js" target="tools/blazor" />
|
||||
</files>
|
||||
</package>
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<BlazorBuildReferenceFromSource>true</BlazorBuildReferenceFromSource>
|
||||
<BlazorJsPath>$(MSBuildThisFileDirectory)../../../src/Microsoft.AspNetCore.Components.Browser.JS/dist/blazor.*.js</BlazorJsPath>
|
||||
<BlazorJsPath>$(MSBuildThisFileDirectory)../../../src/Microsoft.AspNetCore.Components.Browser.JS/dist/components.*.js</BlazorJsPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="$(MSBuildThisFileDirectory)targets/All.props" />
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project>
|
||||
|
||||
<PropertyGroup Condition="'$(BlazorBuildReferenceFromSource)'==''">
|
||||
<BlazorJsPath>$(MSBuildThisFileDirectory)../tools/blazor/blazor.*.js</BlazorJsPath>
|
||||
<BlazorJsPath>$(MSBuildThisFileDirectory)../tools/blazor/components.*.js</BlazorJsPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Label="Blazor build outputs">
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
|
||||
|
||||
<!-- Used by ws-proxy sources only. Remove this once we're able to consume ws-proxy as a NuGet package. -->
|
||||
<PackageReference Include="Mono.Cecil" Version="0.10.0-beta7" />
|
||||
<PackageReference Include="Mono.Cecil" Version="$(MonoCecilPackageVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,6 @@
|
|||
<body>
|
||||
<app>Loading...</app>
|
||||
|
||||
<script src="_framework/blazor.webassembly.js"></script>
|
||||
<script src="_framework/components.webassembly.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,6 @@
|
|||
<body>
|
||||
<app>Loading...</app>
|
||||
|
||||
<script src="_framework/blazor.webassembly.js"></script>
|
||||
<script src="_framework/components.webassembly.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@
|
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
|
||||
<PackageReference Include="xunit" Version="2.3.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
|
||||
<PackageReference Include="Mono.Cecil" Version="0.10.0-beta7" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Blazor.Mono" Version="$(MicrosoftAspNetCoreBlazorMonoPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.Extensions" Version="$(MicrosoftNETSdkRazorPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Razor.Language" Version="$(MicrosoftNETSdkRazorPackageVersion)" />
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
<MicrosoftAspNetCoreHtmlAbstractionsPackageVersion>3.0.0-alpha1-10605</MicrosoftAspNetCoreHtmlAbstractionsPackageVersion>
|
||||
<MicrosoftAspNetCoreRazorDesignPackageVersion>3.0.0-alpha1-10605</MicrosoftAspNetCoreRazorDesignPackageVersion>
|
||||
<MicrosoftExtensionsDependencyInjectionPackageVersion>3.0.0-alpha1-10605</MicrosoftExtensionsDependencyInjectionPackageVersion>
|
||||
<MonoCecilPackageVersion>0.10.1</MonoCecilPackageVersion>
|
||||
<SignalRPackageVersion>3.0.0-alpha1-10605</SignalRPackageVersion>
|
||||
<TemplateBlazorPackageVersion>0.8.0-preview1-20181122.3</TemplateBlazorPackageVersion>
|
||||
<TemplateRazorDesignPackageVersion>2.1.2</TemplateRazorDesignPackageVersion>
|
||||
|
|
|
|||
|
|
@ -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 />
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
// 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.
|
||||
|
||||
namespace ComponentsApp.App
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
// TODO: Remove entry point
|
||||
// Currently it's required because .Components.Build won't generate the boot JSON correctly without seeing an entrypoint
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<div class="top-row pl-4 navbar navbar-dark">
|
||||
<a class="navbar-brand" href="">Blazor app</a>
|
||||
<div class="top-row pl-4 navbar navbar-dark">
|
||||
<a class="navbar-brand" href="">Razor Components</a>
|
||||
<button class="navbar-toggler" onclick=@ToggleNavMenu>
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ComponentsApp.App;
|
||||
|
||||
namespace ComponentsApp.Server
|
||||
{
|
||||
|
|
@ -12,11 +11,7 @@ namespace ComponentsApp.Server
|
|||
{
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// Adds the Server-Side Blazor services, and those registered by the client startup.
|
||||
services.AddServerSideBlazor<App.Startup>();
|
||||
|
||||
// Since Blazor is running on the server, we can use an application service
|
||||
// to read the forecast data.
|
||||
services.AddRazorComponents<App.Startup>();
|
||||
services.AddSingleton<WeatherForecastService, DefaultWeatherForecastService>();
|
||||
}
|
||||
|
||||
|
|
@ -27,8 +22,8 @@ namespace ComponentsApp.Server
|
|||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
// Use component registrations and static files from the client startup.
|
||||
app.UseServerSideBlazor<App.Startup>();
|
||||
app.UseStaticFiles();
|
||||
app.UseRazorComponents<App.Startup>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 54 KiB After Width: | Height: | Size: 54 KiB |
|
|
@ -3,7 +3,7 @@
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<title>Server Side Blazor</title>
|
||||
<title>Razor Components</title>
|
||||
<base href="/" />
|
||||
<link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />
|
||||
<link href="css/site.css" rel="stylesheet" />
|
||||
|
|
@ -11,6 +11,6 @@
|
|||
<body>
|
||||
<app>Loading...</app>
|
||||
|
||||
<script src="_framework/blazor.server.js"></script>
|
||||
<script src="_framework/components.server.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Description>JavaScript runtime files needed for ASP.NET Core Components browser rendering.</Description>
|
||||
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
|
||||
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
|
||||
|
|
@ -22,13 +22,13 @@
|
|||
<Exec Command="npm ci" />
|
||||
</Target>
|
||||
|
||||
<Target Name="RunWebpack" AfterTargets="ResolveReferences" Inputs="@(WebpackInputs)" Outputs="dist\blazor.webassembly.js;dist\blazor.server.js" DependsOnTargets="EnsureNpmRestored">
|
||||
<Target Name="RunWebpack" AfterTargets="ResolveReferences" Inputs="@(WebpackInputs)" Outputs="dist\components.webassembly.js;dist\components.server.js" DependsOnTargets="EnsureNpmRestored">
|
||||
<RemoveDir Directories="dist" />
|
||||
<Exec Command="npm run build:debug" Condition="'$(Configuration)' == 'Debug'" />
|
||||
<Exec Command="npm run build:production" Condition="'$(Configuration)' != 'Debug'" />
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="dist\blazor.webassembly.js" LogicalName="blazor./blazor.webassembly.js" />
|
||||
<EmbeddedResource Include="dist\blazor.server.js" LogicalName="blazor./blazor.server.js" />
|
||||
<EmbeddedResource Include="dist\components.webassembly.js" LogicalName="blazor./components.webassembly.js" />
|
||||
<EmbeddedResource Include="dist\components.server.js" LogicalName="blazor./components.server.js" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ module.exports = (env, args) => ({
|
|||
rules: [{ test: /\.ts?$/, loader: 'ts-loader' }]
|
||||
},
|
||||
entry: {
|
||||
'blazor.webassembly': './src/Boot.WebAssembly.ts',
|
||||
'blazor.server': './src/Boot.Server.ts',
|
||||
'components.webassembly': './src/Boot.WebAssembly.ts',
|
||||
'components.server': './src/Boot.Server.ts',
|
||||
},
|
||||
output: { path: path.join(__dirname, '/dist'), filename: '[name].js' }
|
||||
});
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||
return null;
|
||||
}
|
||||
|
||||
private static void SetCacheHeaders(StaticFileResponseContext ctx)
|
||||
internal static void SetCacheHeaders(StaticFileResponseContext ctx)
|
||||
{
|
||||
// By setting "Cache-Control: no-cache", we're allowing the browser to store
|
||||
// a cached copy of the response, but telling it that it must check with the
|
||||
|
|
|
|||
|
|
@ -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>(
|
||||
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));
|
||||
}
|
||||
|
||||
// Use embedded static content for /_framework
|
||||
builder.Map("/_framework", frameworkBuilder =>
|
||||
{
|
||||
UseFrameworkFiles(frameworkBuilder);
|
||||
});
|
||||
|
||||
// Use SPA fallback routing for anything else
|
||||
builder.UseSpa(spa => { });
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
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"": [] }");
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
// 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.Http;
|
||||
|
||||
namespace Microsoft.AspNetCore.Builder
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods to configure an <see cref="IApplicationBuilder"/> for Server-Side Blazor.
|
||||
/// These are just shorthand for combining UseSignalR with UseBlazor.
|
||||
/// </summary>
|
||||
public static class ServerSideBlazorApplicationBuilderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers Server-Side Blazor in the pipeline.
|
||||
/// </summary>
|
||||
/// <param name="builder">The <see cref="IApplicationBuilder"/>.</param>
|
||||
/// <typeparam name="TStartup">A Blazor startup type.</typeparam>
|
||||
/// <returns>The <see cref="IApplicationBuilder"/>.</returns>
|
||||
public static IApplicationBuilder UseServerSideBlazor<TStartup>(
|
||||
this IApplicationBuilder builder)
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(builder));
|
||||
}
|
||||
|
||||
// WARNING: Don't add extra setup logic here. It's important for
|
||||
// UseServerSideBlazor just to be shorthand for UseSignalR+UseBlazor,
|
||||
// so that people who want to call those two manually instead can
|
||||
// also do so. That's needed for people using Azure SignalR.
|
||||
|
||||
// TODO: Also allow configuring the endpoint path.
|
||||
return UseSignalRWithBlazorHub(builder, BlazorHub.DefaultPath)
|
||||
.UseBlazor<TStartup>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers Server-Side Blazor in the pipeline.
|
||||
/// </summary>
|
||||
/// <param name="builder">The <see cref="IApplicationBuilder"/>.</param>
|
||||
/// <param name="options">A <see cref="BlazorOptions"/> instance used to configure the Blazor file provider.</param>
|
||||
/// <returns>The <see cref="IApplicationBuilder"/>.</returns>
|
||||
public static IApplicationBuilder UseServerSideBlazor(
|
||||
this IApplicationBuilder builder,
|
||||
BlazorOptions options)
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(builder));
|
||||
}
|
||||
|
||||
if (options == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(options));
|
||||
}
|
||||
|
||||
// WARNING: Don't add extra setup logic here. It's important for
|
||||
// UseServerSideBlazor just to be shorthand for UseSignalR+UseBlazor,
|
||||
// so that people who want to call those two manually instead can
|
||||
// also do so. That's needed for people using Azure SignalR.
|
||||
|
||||
// TODO: Also allow configuring the endpoint path.
|
||||
return UseSignalRWithBlazorHub(builder, BlazorHub.DefaultPath)
|
||||
.UseBlazor(options);
|
||||
}
|
||||
|
||||
private static IApplicationBuilder UseSignalRWithBlazorHub(
|
||||
IApplicationBuilder builder, PathString path)
|
||||
{
|
||||
return builder.UseSignalR(route => route.MapHub<BlazorHub>(BlazorHub.DefaultPath));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -12,33 +12,17 @@ using Microsoft.JSInterop;
|
|||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods to configure an <see cref="IServiceCollection"/> for Server-Side Blazor.
|
||||
/// Extension methods to configure an <see cref="IServiceCollection"/> for interactive components.
|
||||
/// </summary>
|
||||
public static class ServerSideBlazorServiceCollectionExtensions
|
||||
public static class RazorComponentsServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds Server-Side Blazor services to the service collection.
|
||||
/// Adds Razor Component services to the service collection.
|
||||
/// </summary>
|
||||
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
|
||||
/// <param name="startupType">A Razor Components project startup type.</param>
|
||||
/// <returns>The <see cref="IServiceCollection"/>.</returns>
|
||||
public static IServiceCollection AddServerSideBlazor(
|
||||
this IServiceCollection services)
|
||||
{
|
||||
if (services == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(services));
|
||||
}
|
||||
|
||||
return AddServerSideBlazor(services, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds Server-Side Blazor services to the service collection.
|
||||
/// </summary>
|
||||
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
|
||||
/// <param name="startupType">A Blazor startup type.</param>
|
||||
/// <returns>The <see cref="IServiceCollection"/>.</returns>
|
||||
public static IServiceCollection AddServerSideBlazor(
|
||||
public static IServiceCollection AddRazorComponents(
|
||||
this IServiceCollection services,
|
||||
Type startupType)
|
||||
{
|
||||
|
|
@ -52,16 +36,16 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
throw new ArgumentNullException(nameof(startupType));
|
||||
}
|
||||
|
||||
return AddServerSideBlazorCore(services, startupType);
|
||||
return AddRazorComponentsCore(services, startupType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds Server-Side Blazor services to the service collection.
|
||||
/// Adds Razor Component app services to the service collection.
|
||||
/// </summary>
|
||||
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
|
||||
/// <typeparam name="TStartup">A Blazor startup type.</typeparam>
|
||||
/// <typeparam name="TStartup">A Components app startup type.</typeparam>
|
||||
/// <returns>The <see cref="IServiceCollection"/>.</returns>
|
||||
public static IServiceCollection AddServerSideBlazor<TStartup>(
|
||||
public static IServiceCollection AddRazorComponents<TStartup>(
|
||||
this IServiceCollection services)
|
||||
{
|
||||
if (services == null)
|
||||
|
|
@ -69,14 +53,14 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
throw new ArgumentNullException(nameof(services));
|
||||
}
|
||||
|
||||
return AddServerSideBlazorCore(services, typeof(TStartup));
|
||||
return AddRazorComponentsCore(services, typeof(TStartup));
|
||||
}
|
||||
|
||||
private static IServiceCollection AddServerSideBlazorCore(
|
||||
private static IServiceCollection AddRazorComponentsCore(
|
||||
IServiceCollection services,
|
||||
Type startupType)
|
||||
{
|
||||
AddStandardServerSideBlazorServices(services);
|
||||
AddStandardRazorComponentsServices(services);
|
||||
|
||||
if (startupType != null)
|
||||
{
|
||||
|
|
@ -94,7 +78,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
if (circuitFactoryOptions.StartupActions.ContainsKey(endpoint))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Multiple Server Side Blazor entries are configured to use " +
|
||||
"Multiple Components app entries are configured to use " +
|
||||
$"the same endpoint '{endpoint}'.");
|
||||
}
|
||||
|
||||
|
|
@ -108,11 +92,11 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
return services;
|
||||
}
|
||||
|
||||
private static void AddStandardServerSideBlazorServices(IServiceCollection services)
|
||||
private static void AddStandardRazorComponentsServices(IServiceCollection services)
|
||||
{
|
||||
// Here we add a bunch of services that don't vary in any way based on the
|
||||
// user's configuration. So even if the user has multiple independent server-side
|
||||
// Blazor entrypoints, this lot is the same and repeated registrations are a no-op.
|
||||
// Components entrypoints, this lot is the same and repeated registrations are a no-op.
|
||||
services.TryAddSingleton<CircuitFactory, DefaultCircuitFactory>();
|
||||
services.TryAddScoped<ICircuitAccessor, DefaultCircuitAccessor>();
|
||||
services.TryAddScoped<Circuit>(s => s.GetRequiredService<ICircuitAccessor>().Circuit);
|
||||
|
|
@ -122,7 +106,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
|
||||
// We've discussed with the SignalR team and believe it's OK to have repeated
|
||||
// calls to AddSignalR (making the nonfirst ones no-ops). If we want to change
|
||||
// this in the future, we could change AddServerSideBlazor to be an extension
|
||||
// this in the future, we could change AddComponents to be an extension
|
||||
// method on ISignalRServerBuilder so the developer always has to chain it onto
|
||||
// their own AddSignalR call. For now we're keeping it like this because it's
|
||||
// simpler for developers in common cases.
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Description>Runtime server features for ASP.NET Core Components.</Description>
|
||||
<IsProductPackage>true</IsProductPackage>
|
||||
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -16,11 +17,17 @@
|
|||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="$(SignalRPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="$(AspNetCorePackageVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="$(AspNetCorePackageVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="$(AspNetCorePackageVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="$(AspNetCorePackageVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Microsoft.AspNetCore.Components.Browser\Microsoft.AspNetCore.Components.Browser.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- We need .Browser.JS to build first so we can embed its .js output -->
|
||||
<ProjectReference Include="..\Microsoft.AspNetCore.Components.Browser.JS\Microsoft.AspNetCore.Components.Browser.JS.csproj" ReferenceOutputAssembly="false" />
|
||||
<EmbeddedResource Include="..\Microsoft.AspNetCore.Components.Browser.JS\dist\components.server.js" LogicalName="frameworkFiles\%(Filename)%(Extension)" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests
|
|||
[Fact]
|
||||
public void HasTitle()
|
||||
{
|
||||
Assert.Equal("Server Side Blazor", Browser.Title);
|
||||
Assert.Equal("Razor Components", Browser.Title);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -18,12 +18,12 @@
|
|||
}
|
||||
|
||||
(function () {
|
||||
// Load either blazor.webassembly.js or blazor.server.js depending
|
||||
// Load either components.webassembly.js or components.server.js depending
|
||||
// on the hash part of the URL. This is just to give a way for the
|
||||
// test runner to make the selection.
|
||||
var src = location.hash === '#server'
|
||||
? 'blazor.server.js'
|
||||
: 'blazor.webassembly.js';
|
||||
? 'components.server.js'
|
||||
: 'components.webassembly.js';
|
||||
document.write('<script src="_framework/' + src + '"><' + '/script>');
|
||||
})();
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace TestServer
|
|||
{
|
||||
options.AddPolicy("AllowAll", _ => { /* Controlled below */ });
|
||||
});
|
||||
services.AddServerSideBlazor<BasicTestApp.Startup>();
|
||||
services.AddRazorComponents<BasicTestApp.Startup>();
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
|
|
|||
Loading…
Reference in New Issue