Begin on serving .NET assemblies from ReferencedAssemblyFileProvider
This commit is contained in:
parent
9b95b68dbf
commit
3b01daf15a
|
|
@ -9,8 +9,8 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\HostedInAspNet.Client\HostedInAspNet.Client.csproj" ReferenceOutputAssembly="false" />
|
|
||||||
<ProjectReference Include="..\..\src\Microsoft.Blazor.Server\Microsoft.Blazor.Server.csproj" />
|
<ProjectReference Include="..\..\src\Microsoft.Blazor.Server\Microsoft.Blazor.Server.csproj" />
|
||||||
|
<ProjectReference Include="..\HostedInAspNet.Client\HostedInAspNet.Client.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ namespace HostedInAspNet.Server
|
||||||
app.UseBlazorDevelopmentServer("../HostedInAspNet.Client");
|
app.UseBlazorDevelopmentServer("../HostedInAspNet.Client");
|
||||||
}
|
}
|
||||||
|
|
||||||
app.UseBlazor();
|
app.UseBlazor<Client.Program>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,29 +15,7 @@ namespace MonoSanity
|
||||||
{
|
{
|
||||||
app.UseDeveloperExceptionPage();
|
app.UseDeveloperExceptionPage();
|
||||||
app.UseFileServer();
|
app.UseFileServer();
|
||||||
app.UseBlazor();
|
app.UseBlazor<MonoSanityClient.Examples>();
|
||||||
|
|
||||||
ServeSingleStaticFile(app,
|
|
||||||
"/clientBin/MonoSanityClient.dll",
|
|
||||||
typeof(Examples).Assembly.Location);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ServeSingleStaticFile(IApplicationBuilder app, string url, string physicalPath)
|
|
||||||
{
|
|
||||||
// This is not implemented efficiently (e.g., doesn't support cache control headers)
|
|
||||||
// so don't use this in real applications. Use 'UseStaticFiles' or similar instead.
|
|
||||||
app.Use((context, next) =>
|
|
||||||
{
|
|
||||||
if (context.Request.Path == url)
|
|
||||||
{
|
|
||||||
context.Response.ContentType = MediaTypeNames.Application.Octet;
|
|
||||||
return File.OpenRead(physicalPath).CopyToAsync(context.Response.Body);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return next();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Mono sanity check</title>
|
<title>Mono sanity check</title>
|
||||||
|
|
@ -40,7 +40,7 @@
|
||||||
|
|
||||||
<script src="loader.js"></script>
|
<script src="loader.js"></script>
|
||||||
<script>
|
<script>
|
||||||
initMono(['/clientBin/MonoSanityClient.dll'], function () {
|
initMono(['/_framework/_bin/MonoSanityClient.dll'], function () {
|
||||||
var buttons = document.getElementsByTagName('button');
|
var buttons = document.getElementsByTagName('button');
|
||||||
for (var i = 0; i < buttons.length; i++) {
|
for (var i = 0; i < buttons.length; i++) {
|
||||||
buttons[i].disabled = false;
|
buttons[i].disabled = false;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ using System.Text;
|
||||||
|
|
||||||
namespace MonoSanityClient
|
namespace MonoSanityClient
|
||||||
{
|
{
|
||||||
public static class Examples
|
public class Examples
|
||||||
{
|
{
|
||||||
public static string AddNumbers(int a, int b)
|
public static string AddNumbers(int a, int b)
|
||||||
=> (a + b).ToString();
|
=> (a + b).ToString();
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,8 @@ async function boot() {
|
||||||
|
|
||||||
// Determine the URLs of the assemblies we want to load
|
// Determine the URLs of the assemblies we want to load
|
||||||
const loadAssemblyUrls = [entryPoint]
|
const loadAssemblyUrls = [entryPoint]
|
||||||
.concat(referenceAssemblies) // Developer-specified references
|
.concat(referenceAssemblies)
|
||||||
.concat(['Microsoft.Blazor.dll']) // Standard references
|
.map(filename => `/_framework/_bin/${filename}`);
|
||||||
.map(filename => `/_bin/${filename}`);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await platform.start(loadAssemblyUrls);
|
await platform.start(loadAssemblyUrls);
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ namespace Microsoft.Blazor.DevHost.Server
|
||||||
{
|
{
|
||||||
app.UseDeveloperExceptionPage();
|
app.UseDeveloperExceptionPage();
|
||||||
app.UseBlazorDevelopmentServer(".");
|
app.UseBlazorDevelopmentServer(".");
|
||||||
app.UseBlazor();
|
app.UseBlazor<object>(); // TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,14 @@ namespace Microsoft.AspNetCore.Builder
|
||||||
{
|
{
|
||||||
public static class BlazorAppBuilderExtensions
|
public static class BlazorAppBuilderExtensions
|
||||||
{
|
{
|
||||||
public static void UseBlazor(this IApplicationBuilder applicationBuilder)
|
public static void UseBlazor<TProgram>(this IApplicationBuilder applicationBuilder)
|
||||||
{
|
{
|
||||||
|
var clientAppAssembly = typeof(TProgram).Assembly;
|
||||||
|
|
||||||
applicationBuilder.UseStaticFiles(new StaticFileOptions
|
applicationBuilder.UseStaticFiles(new StaticFileOptions
|
||||||
{
|
{
|
||||||
RequestPath = "/_framework",
|
RequestPath = "/_framework",
|
||||||
FileProvider = ClientFileProvider.Instantiate(),
|
FileProvider = ClientFileProvider.Instantiate(clientAppAssembly),
|
||||||
ContentTypeProvider = CreateContentTypeProvider(),
|
ContentTypeProvider = CreateContentTypeProvider(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,17 @@
|
||||||
using Microsoft.Blazor.Browser;
|
using Microsoft.Blazor.Browser;
|
||||||
using Microsoft.Blazor.Mono;
|
using Microsoft.Blazor.Mono;
|
||||||
using Microsoft.Extensions.FileProviders;
|
using Microsoft.Extensions.FileProviders;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace Microsoft.Blazor.Server.ClientFilesystem
|
namespace Microsoft.Blazor.Server.ClientFilesystem
|
||||||
{
|
{
|
||||||
internal static class ClientFileProvider
|
internal static class ClientFileProvider
|
||||||
{
|
{
|
||||||
public static IFileProvider Instantiate()
|
public static IFileProvider Instantiate(Assembly clientApp)
|
||||||
=> new CompositeFileProvider(
|
=> new CompositeFileProvider(
|
||||||
MonoStaticFileProvider.JsFiles,
|
MonoStaticFileProvider.JsFiles,
|
||||||
MonoStaticFileProvider.BclFiles, // TODO: Stop serving these, and serve the ReferencedAssemblyFileProvider instead
|
MonoStaticFileProvider.BclFiles, // TODO: Stop serving these, and serve the ReferencedAssemblyFileProvider instead
|
||||||
BlazorBrowserFileProvider.Instance);
|
BlazorBrowserFileProvider.Instance,
|
||||||
|
new ReferencedAssemblyFileProvider(clientApp, MonoStaticFileProvider.BclFiles));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue