DuMes.EndpointModule.BasicSystem
5.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package DuMes.EndpointModule.BasicSystem --version 5.0.0
NuGet\Install-Package DuMes.EndpointModule.BasicSystem -Version 5.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DuMes.EndpointModule.BasicSystem" Version="5.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DuMes.EndpointModule.BasicSystem" Version="5.0.0" />
<PackageReference Include="DuMes.EndpointModule.BasicSystem" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DuMes.EndpointModule.BasicSystem --version 5.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DuMes.EndpointModule.BasicSystem, 5.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DuMes.EndpointModule.BasicSystem@5.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DuMes.EndpointModule.BasicSystem&version=5.0.0
#tool nuget:?package=DuMes.EndpointModule.BasicSystem&version=5.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
appsettings.json 文件内容
{
"Logging": {
"LogLevel": {
"Default": "Warning",
"Microsoft.AspNetCore": "Warning"
}
},
"HttpPort": 14100,
"Http2Port": 14200,
"JwtTokenConfig": {
"PublicKey": "0196a39c-535e-498e-1cd4-82d579f33fcb",
"Issuer": "SIASUN",
"Audience": "ALL",
"Expiration": 1440
}
}
appsettings.Development.json 文件内容
编译Release版本时创建appsettings.Production.json文件
{
"DuMesCoreGrpcServiceAddress": "http://localhost:14200",
"CrossOriginUrls": [
"http://localhost:9000",
"http://127.0.0.1:9000"
],
"RedisConfig": {
"Host": "127.0.0.1",
"Port": 6379,
"Password": "siasun@sh",
"CachePrefix": "DuMes5.0:"
},
"DataBaseConnectionConfig": [
{
"Name": "system",
"ConnectionString": "HOST=10.211.55.4;PORT=5432;DATABASE=DuMesV5;searchpath=system;USER ID=postgres;PASSWORD=siasun@SH;MaxPoolSize=512",
"DbType": "PostgreSQL"
},
{
"Name": "log",
"ConnectionString": "PORT=5432;DATABASE=DuMesV5;HOST=10.211.55.4;searchpath=log;USER ID=postgres;PASSWORD=siasun@SH;MaxPoolSize=512",
"DbType": "PostgreSQL"
}
]
}
dockerfile 文件内容
# 获取aspnet10.0 运行时
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime
# 指定工作目录
WORKDIR /app
# 将当前目录下所有文件复制到工作目录,注意 . . 中间是有空格的
COPY ./ ./
# 设置环境变量,可设置多个,如urls...
ENV ASPNETCORE_ENVIRONMENT Production
# 声明程序入口
ENTRYPOINT ["dotnet", "项目名称.dll"]
Program.cs 文件内容
var options = new WebApplicationOptions
{
Args = args,
ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : null
};
var builder = WebApplication.CreateBuilder(options);
builder.WebHost.ConfigureKestrel(o => { o.Limits.MaxRequestBodySize = 104857600; });
if (OperatingSystem.IsWindows() && WindowsServiceHelpers.IsWindowsService())
//增加windows服务
builder.Host.UseWindowsService();
#region 注册系统基础组件
//指定端口
var httpPort = builder.Configuration.GetSection("HttpPort").Get<int>();
var http2Port = builder.Configuration.GetSection("Http2Port").Get<int>();
//注册端口
builder.WebHost.UseKestrel(config =>
{
config.Listen(IPAddress.Any, httpPort);
config.Listen(IPAddress.Any, http2Port,
kestrelOptions => { kestrelOptions.Protocols = HttpProtocols.Http2; });
});
//添加 HTTP 上下文访问器
builder.Services.AddHttpContextAccessor();
#endregion
#region 数据存储组件
//注册SqlSugar组件
var connectionConfigList = builder.Configuration.GetSection("DataBaseConnectionConfig").Get<SqlSugarConnectionConfig[]>();
builder.Services.AddSqlSugarIocExpansion(connectionConfigList);
//初始化Redis客户端
var redisConfig = builder.Configuration.GetSection("RedisConfig").Get<RedisExpansionConfig>();
ArgumentNullException.ThrowIfNull(redisConfig);
RedisExpansionRegister.InitializeRedisExpansion(redisConfig);
#endregion
#region 注册FastEndpint组件
//注册Grpc执行服务器
builder.Services.AddHandlerServer();
//注册认证模块、任务存储提供程序、响应缓存
builder.Services.AddAuthenticationJwtBearerExpansion(builder.Configuration)
.AddCrossOriginExtension(builder.Configuration.GetSection("CrossOriginUrls").Get<string[]>())
// .AddJobQueues<JobGuidRecord, JobStorageProvider>()
.AddResponseCaching();
//自动添加模块
EndpointModuleExpansion.AutoAddModules(builder.Services, builder.Configuration, SystemConstKey.EndpointModulePattern);
#endregion
#region 注册SignalR
builder.Services.AddSignalR(signalROptions => { signalROptions.EnableDetailedErrors = builder.Environment.IsDevelopment(); })
.AddJsonProtocol(jsonProtocolOptions => jsonProtocolOptions.PayloadSerializerOptions.PropertyNamingPolicy = null)
.AddStackExchangeRedis(redisConfig.SignalRConnectionString(), o =>
{
o.Configuration.ChannelPrefix = new RedisChannel(redisConfig.CachePrefix, RedisChannel.PatternMode.Auto);
o.Configuration.DefaultDatabase = EndpointsRedisIndex.Default;
});
builder.Services.AddSingleton<IUserIdProvider, SignalRCustomUserProvider>();
#endregion
//注册国际化语言扩展
builder.Services.AddLanguageExtension(["zh-CN", "en"]);
//注册初始化服务
builder.Services.AddHostedService<ProgramHostedService>();
//注册定时任务
builder.Services.AddHangFireExpansion();
var app = builder.Build();
//使用国际化语言扩展
app.UseLanguageExtension();
#region 使用FastEndpint组件
//服务端注册调用
app.MapHandlers(_ =>
{
//远程命令
});
//客户端映射远程Grpc调用
app.MapRemote($"{builder.Configuration["DuMesSystemGrpcServiceAddress"]}", _ =>
{
//远程命令注册
});
//使用FastEndpoint扩展
app.UseFastEndpointExpansion();
// app.UseJobQueues();
#endregion
#region 使用SignalR
app.MapHub<SystemSignalRHub>("/system/notification");
#endregion
#region 启动HangFire
app.UseHangfireDashboard(options: new DashboardOptions
{
Authorization = [new CustomAuthorizeFilter()]
});
#endregion
app.Run();
ProgramHostedService.cs 文件内容
public class ProgramHostedService(IHostApplicationLifetime applicationLifetime, IConfiguration configuration) : IHostedService
{
public Task StartAsync(CancellationToken cancellationToken)
{
// 注册应用程序完全启动后的回调
applicationLifetime.ApplicationStarted.Register(() =>
{
var moduleName = Assembly.GetExecutingAssembly().GetName().Name!;
DoSerilog.GetConsoleLogger().Information("正在加载 {ModuleName} [多脉系统配置]服务的模块", moduleName);
//自动模块初始化
EndpointModuleExpansion.AutoModuleInitialize(SystemConstKey.EndpointModulePattern)
.ConfigureAwait(false).GetAwaiter().GetResult();
var redis = RedisHelp.GetClient(EndpointsRedisIndex.Default);
//加载系统需要使用的缓存
var parameterList = DbScoped.SugarScope.QueryableWithAttr<ParameterEntity>()
.Where(o => o.IsDelete == false).ToList();
foreach (var parameter in parameterList)
redis.Set(SystemCacheKey.GetParameterCacheKey(parameter.Code), parameter.Content);
var tokenList = DbScoped.SugarScope.QueryableWithAttr<ApiKeyEntity>()
.Where(o => o.IsDelete == false).ToList();
foreach (var token in tokenList)
{
var apiKey = new ApiKeyCacheModel(token.Id, token.Name, token.ExpirationTime);
redis.SetAsync(EndpointCacheKey.GetApiKeyCacheKey(token.Token), apiKey);
}
//同步网页/手机端权限
new SyncRoleWebPermissionEvent().PublishAsync(Mode.WaitForNone, cancellationToken)
.ConfigureAwait(false).GetAwaiter().GetResult();
new SyncRoleMobilePermissionEvent().PublishAsync(Mode.WaitForNone, cancellationToken)
.ConfigureAwait(false).GetAwaiter().GetResult();
new SyncWebMenuToNavigationWebCacheEvent().PublishAsync(Mode.WaitForNone, cancellationToken)
.ConfigureAwait(false).GetAwaiter().GetResult();
DoSerilog.GetConsoleLogger().Information("{ModuleName} [多脉系统配置]服务启动完成", moduleName);
//定时任务启动
BasicSystemHangFireTask.Run();
//指定端口
var httpPort = configuration.GetSection("HttpPort").Get<int>();
var http2Port = configuration.GetSection("Http2Port").Get<int>();
DoSerilog.GetConsoleLogger().Information("正在监听 Http 0.0.0.0:{HttpPort},Http2 0.0.0.0:{Http2Port}", httpPort, http2Port);
});
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
// 在应用停止时执行的逻辑
return Task.CompletedTask;
}
}
模块使用方法
需要创建一个ModuleRegister类,继承 IEndpointModule并实现方法
public void AddModule(IServiceCollection services, IConfiguration configuration)
{
services.AddFastEndpoints();
services.SwaggerDocument(o =>
{
o.MaxEndpointVersion = 0;
o.DocumentSettings = s =>
{
s.DocumentName = "系统基础模块接口";
s.Title = "多脉快速开发框架";
s.Version = "v0";
s.ApiGroupNames = EndpointGroup.TagDescriptionDictionary.Keys.ToArray();
};
o.AutoTagPathSegmentIndex = 0;
o.ShortSchemaNames = true;
o.TagDescriptions = t =>
{
foreach (var tag in EndpointGroup.TagDescriptionDictionary.Keys)
t[tag] = EndpointGroup.TagDescriptionDictionary[tag];
};
});
}
public async Task InitializeModule()
{
var module = Assembly.GetExecutingAssembly().GetName();
var redis = RedisHelp.GetClient(EndpointsRedisIndex.Default);
var oldVersion = await redis.GetAsync<Version>(EndpointCacheKey.GetModuleVersionCacheKey(module.Name));
if (module.Version?.CompareTo(oldVersion) > 0)
{
DoSerilog.GetConsoleLogger().Information("开始 {ModuleName} {Version} 模块的数据库初始化工作...请稍后", module.Name, $"V{module.Version}");
//将所有标记为模型优先的数据表同步到其对应的数据库中
DataTableTools.SyncModuleAllCodeFirstModelToDatabase(typeof(SystemModuleTable).Assembly);
DoSerilog.GetConsoleLogger().Information("同步到数据模型到对应数据库结束,开始初始化:{ModuleName} {Version} 模块的最新的配置数据", module.Name, $"V{module.Version}");
...实现加载模块最初数据方法
DoSerilog.GetConsoleLogger().Information("{ModuleName} {Version} 模块最新的配置数据已同步完成", module.Name, $"V{module.Version}");
await redis.SetAsync(EndpointCacheKey.GetModuleVersionCacheKey(module.Name), module.Version);
}
DoSerilog.GetConsoleLogger().Information("{ModuleName} {Version} 模块的所有加载和初始化工作已完成", module.Name, $"V{module.Version}");
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- DuMes.Contracts.BasicSystem (>= 5.0.2)
- DuMes.Expansion.File (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.