-
-
Notifications
You must be signed in to change notification settings - Fork 382
Expand file tree
/
Copy pathServiceCollectionExtensions.cs
More file actions
70 lines (57 loc) · 2.5 KB
/
ServiceCollectionExtensions.cs
File metadata and controls
70 lines (57 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
using Longbow.Tasks.Services;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Options;
using System.Text.Encodings.Web;
using System.Text.Unicode;
namespace Microsoft.Extensions.DependencyInjection;
static class ServiceCollectionExtensions
{
public static IServiceCollection AddBootstrapBlazorServerService(this IServiceCollection services)
{
// 增加中文编码支持网页源码显示汉字
services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.All));
// 增加错误日志,并过滤已知的防伪 Token 解密噪音日志
services.AddLogging(logging =>
{
logging.AddFileLogger();
logging.AddFilter("Microsoft.AspNetCore.Antiforgery", LogLevel.None);
});
// 增加多语言支持配置信息
services.AddRequestLocalization<IOptions<BootstrapBlazorOptions>>((localizerOption, blazorOption) =>
{
var supportedCultures = blazorOption.Value.GetSupportedCultures();
localizerOption.SupportedCultures = supportedCultures;
localizerOption.SupportedUICultures = supportedCultures;
});
services.AddControllers();
// 增加 SignalR 服务数据传输大小限制配置
services.Configure<HubOptions>(option => option.MaximumReceiveMessageSize = null);
// 增加后台任务服务
services.AddTaskServices();
services.AddHostedService<ClearTempFilesService>();
services.AddHostedService<MockReceiveSocketServerService>();
services.AddHostedService<MockSendReceiveSocketServerService>();
services.AddHostedService<MockCustomProtocolSocketServerService>();
services.AddHostedService<MockDisconnectServerService>();
if (OperatingSystem.IsWindows())
{
services.AddOpcDaServer();
}
else
{
// 增加 OpcDa 模拟服务(给 Linux 平台使用)
services.AddMockOpcDaServer();
}
// 增加 ITcpSocketFactory 服务
services.AddTcpSocketFactory();
// 增加 IModbusFactory 服务
services.AddModbusFactory();
// 增加通用服务
services.AddBootstrapBlazorServices();
return services;
}
}