Refactoring middleware configuration API
This commit is contained in:
parent
a4c74234b4
commit
79a4016b13
|
|
@ -7,27 +7,40 @@ using Microsoft.Extensions.FileProviders;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net.Mime;
|
using System.Net.Mime;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Builder
|
namespace Microsoft.AspNetCore.Builder
|
||||||
{
|
{
|
||||||
public static class BlazorAppBuilderExtensions
|
public static class BlazorAppBuilderExtensions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Configures the middleware pipeline to work with Blazor.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="applicationBuilder"></param>
|
||||||
|
/// <param name="clientAssemblyName"
|
||||||
|
/// >The name of the client assembly relative to the current bin directory.</param>
|
||||||
public static void UseBlazor(
|
public static void UseBlazor(
|
||||||
this IApplicationBuilder applicationBuilder,
|
this IApplicationBuilder applicationBuilder,
|
||||||
string clientAssemblyName)
|
string clientAssemblyName)
|
||||||
{
|
{
|
||||||
var binDir = Path.GetDirectoryName(typeof(BlazorConfig).Assembly.Location);
|
var binDir = Path.GetDirectoryName(typeof(BlazorConfig).Assembly.Location);
|
||||||
var clientAssemblyPath = Path.Combine(binDir, $"{clientAssemblyName}.dll");
|
var clientAssemblyPath = Path.Combine(binDir, $"{clientAssemblyName}.dll");
|
||||||
applicationBuilder.UseBlazorInternal(clientAssemblyPath);
|
applicationBuilder.UseBlazor(new BlazorOptions
|
||||||
|
{
|
||||||
|
ClientAssemblyPath = clientAssemblyPath,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Change this combination of APIs to make it possible to supply either
|
/// <summary>
|
||||||
// an assembly name (resolved to current bin dir) or full assembly path
|
/// Configures the middleware pipeline to work with Blazor.
|
||||||
internal static void UseBlazorInternal(
|
/// </summary>
|
||||||
|
/// <param name="applicationBuilder"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
public static void UseBlazor(
|
||||||
this IApplicationBuilder applicationBuilder,
|
this IApplicationBuilder applicationBuilder,
|
||||||
string clientAssemblyPath)
|
BlazorOptions options)
|
||||||
{
|
{
|
||||||
var config = BlazorConfig.Read(clientAssemblyPath);
|
var config = BlazorConfig.Read(options.ClientAssemblyPath);
|
||||||
var clientAppBinDir = Path.GetDirectoryName(config.SourceOutputAssemblyPath);
|
var clientAppBinDir = Path.GetDirectoryName(config.SourceOutputAssemblyPath);
|
||||||
var clientAppDistDir = Path.Combine(clientAppBinDir, "dist");
|
var clientAppDistDir = Path.Combine(clientAppBinDir, "dist");
|
||||||
var distFileProvider = new PhysicalFileProvider(clientAppDistDir);
|
var distFileProvider = new PhysicalFileProvider(clientAppDistDir);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Blazor.Server
|
||||||
|
{
|
||||||
|
public class BlazorOptions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Full path to the client assembly.
|
||||||
|
/// </summary>
|
||||||
|
public string ClientAssemblyPath { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue