Begin on serving .NET assemblies from ReferencedAssemblyFileProvider
This commit is contained in:
parent
9b95b68dbf
commit
3b01daf15a
|
|
@ -9,8 +9,8 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\HostedInAspNet.Client\HostedInAspNet.Client.csproj" ReferenceOutputAssembly="false" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.Blazor.Server\Microsoft.Blazor.Server.csproj" />
|
||||
<ProjectReference Include="..\HostedInAspNet.Client\HostedInAspNet.Client.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace HostedInAspNet.Server
|
|||
app.UseBlazorDevelopmentServer("../HostedInAspNet.Client");
|
||||
}
|
||||
|
||||
app.UseBlazor();
|
||||
app.UseBlazor<Client.Program>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,29 +15,7 @@ namespace MonoSanity
|
|||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
app.UseFileServer();
|
||||
app.UseBlazor();
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
app.UseBlazor<MonoSanityClient.Examples>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<!DOCTYPE html>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Mono sanity check</title>
|
||||
|
|
@ -40,7 +40,7 @@
|
|||
|
||||
<script src="loader.js"></script>
|
||||
<script>
|
||||
initMono(['/clientBin/MonoSanityClient.dll'], function () {
|
||||
initMono(['/_framework/_bin/MonoSanityClient.dll'], function () {
|
||||
var buttons = document.getElementsByTagName('button');
|
||||
for (var i = 0; i < buttons.length; i++) {
|
||||
buttons[i].disabled = false;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.Text;
|
|||
|
||||
namespace MonoSanityClient
|
||||
{
|
||||
public static class Examples
|
||||
public class Examples
|
||||
{
|
||||
public static string AddNumbers(int a, int b)
|
||||
=> (a + b).ToString();
|
||||
|
|
|
|||
|
|
@ -18,9 +18,8 @@ async function boot() {
|
|||
|
||||
// Determine the URLs of the assemblies we want to load
|
||||
const loadAssemblyUrls = [entryPoint]
|
||||
.concat(referenceAssemblies) // Developer-specified references
|
||||
.concat(['Microsoft.Blazor.dll']) // Standard references
|
||||
.map(filename => `/_bin/${filename}`);
|
||||
.concat(referenceAssemblies)
|
||||
.map(filename => `/_framework/_bin/${filename}`);
|
||||
|
||||
try {
|
||||
await platform.start(loadAssemblyUrls);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace Microsoft.Blazor.DevHost.Server
|
|||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
app.UseBlazorDevelopmentServer(".");
|
||||
app.UseBlazor();
|
||||
app.UseBlazor<object>(); // TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,12 +10,14 @@ namespace Microsoft.AspNetCore.Builder
|
|||
{
|
||||
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
|
||||
{
|
||||
RequestPath = "/_framework",
|
||||
FileProvider = ClientFileProvider.Instantiate(),
|
||||
FileProvider = ClientFileProvider.Instantiate(clientAppAssembly),
|
||||
ContentTypeProvider = CreateContentTypeProvider(),
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,15 +4,17 @@
|
|||
using Microsoft.Blazor.Browser;
|
||||
using Microsoft.Blazor.Mono;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Microsoft.Blazor.Server.ClientFilesystem
|
||||
{
|
||||
internal static class ClientFileProvider
|
||||
{
|
||||
public static IFileProvider Instantiate()
|
||||
public static IFileProvider Instantiate(Assembly clientApp)
|
||||
=> new CompositeFileProvider(
|
||||
MonoStaticFileProvider.JsFiles,
|
||||
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