Skip to content

Commit d1acd67

Browse files
committed
refactor: 注入 MockHostEnvironment 实现类
1 parent dabe74b commit d1acd67

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
using Microsoft.Extensions.Configuration;
77
using Microsoft.Extensions.DependencyInjection.Extensions;
8+
using Microsoft.Extensions.Hosting;
89
using System.Globalization;
910

1011
namespace Microsoft.Extensions.DependencyInjection;
@@ -36,6 +37,9 @@ public static IServiceCollection AddBootstrapBlazor(this IServiceCollection serv
3637
services.TryAddSingleton<IZipArchiveService, DefaultZipArchiveService>();
3738
services.TryAddSingleton(typeof(IDispatchService<>), typeof(DefaultDispatchService<>));
3839

40+
// 增加 IHostEnvironment 服务
41+
services.TryAddSingleton<IHostEnvironment, MockWasmHostEnvironment>();
42+
3943
// 增加 OtpOptions 配置支持
4044
services.AddOptionsMonitor<OtpOptions>();
4145

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License
3+
// See the LICENSE file in the project root for more information.
4+
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
5+
6+
using Microsoft.Extensions.FileProviders;
7+
using Microsoft.Extensions.Hosting;
8+
9+
namespace BootstrapBlazor.Components;
10+
11+
class MockWasmHostEnvironment : IHostEnvironment
12+
{
13+
public string EnvironmentName { get; set; } = "Production";
14+
15+
public string ApplicationName { get; set; } = "BootstrapBlazor";
16+
17+
public string ContentRootPath { get; set; } = "";
18+
19+
public IFileProvider ContentRootFileProvider { get; set; } = null!;
20+
}

0 commit comments

Comments
 (0)