NetPro.Startup
6.0.16
dotnet add package NetPro.Startup --version 6.0.16
NuGet\Install-Package NetPro.Startup -Version 6.0.16
<PackageReference Include="NetPro.Startup" Version="6.0.16" />
paket add NetPro.Startup --version 6.0.16
#r "nuget: NetPro.Startup, 6.0.16"
// Install NetPro.Startup as a Cake Addin #addin nuget:?package=NetPro.Startup&version=6.0.16 // Install NetPro.Startup as a Cake Tool #tool nuget:?package=NetPro.Startup&version=6.0.16
NetPro.Satrtup使用
使用
约定
默认站点根目录下所有json自动在配置中生效,通过IConfiguration获取配置,有一些例外的json文件不在此生效:
runtimeconfig.template.json
;startup.json
;global.json
启用服务
通过添加环境变量ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=NetPro.Satrtup,开发环境可以通过设置launchSettings.json来启用NetPro.Satrtup插件
{
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "NetPro.Satrtup"
}
}
生产环境通过设置系统环境方式启用以docker为例
docker run -e ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=NetPro.Satrtup
k8s为例
env:
- name:ASPNETCORE_HOSTINGSTARTUPASSEMBLIES
value:"NetPro.Satrtup"
linux为例
export ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=NetPro.Satrtup
高级用法
更改Startup执行顺序,既中间件的执行顺序
增加startup.json 文件到程序运行目录
{
"NetProCoreStartup": 0,
"NetProCoreStartup1": 1
}
//key为继承INetProStartup的实现类名称
//value为对应的执行顺序
//不区分大小写
//数字越大越靠后执行
覆盖替换指定Startup
感谢KamenRiderKuuga提交的此功能"用于使用自定义Startup替换已有的Startup".
日常开发中,可能我们并不想使用已经内置的Startup实现,比如NetPro.Web.Api包内的ErrorHandlerStartup处理异常操作,
此时我们想用我们自己的实现替换他,就可用到ReplaceStartupAttribute
/// <summary>
/// 自定义异常处理中间件
/// </summary>
[ReplaceStartup("ErrorHandlerStartup")]
public class CustomErrorHandlerStartup : INetProStartup
{
}
此时ErrorHandlerStartup将失效,又ApiStartup所在功能覆盖。
指定配置文件路径(用于整理拆分配置文件):
在appsettings.json
文件中增加配置项ConfigPath
,指定配置文件夹存放路径,例如此处,appsetting.json
中只有这一条配置项:
{
"ConfigPath": "ConfigJsons"
}
所有在程序运行目录ConfigJsons
中的json文件将被读取为配置项,此时,原有的appsetting.json
被拆分为:
E:.
| appsettings.json
| Project.csproj
|
\---ConfigJsons
globalization.json
log.json
mq.json
redis.json
swagger.json
注:这里的配置文件同样支持按环境适配,比如在开发环境下,mq.Development.json
文件中的相应配置项将会生效
可覆盖
在appsetting.json
中可以配置Overridable
属性,这个变量用来决定在appsetting.json
和ConfigPath
中配置文件有相同的配置节点时,是否用ConfigPath
中配置文件的节点来覆盖appsetting.json
中的配置节点,当不配置时默认为true
,即存在相同配置节点时,appsetting.json
中的配置节点会被覆盖,调整这个属性为false
有助于在使用ConfigJsons
整理配置项的同时,将一些经常变动的配置项集中到appsetting.json
进行调整
{
"Overridable": true
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- BetterConsoleTables (>= 2.0.4-rc1)
- Figgle (>= 0.4.0)
- NetPro.TypeFinder (>= 6.0.16)
-
net6.0
- BetterConsoleTables (>= 2.0.4-rc1)
- Figgle (>= 0.4.0)
- NetPro.TypeFinder (>= 6.0.16)
NuGet packages (25)
Showing the top 5 NuGet packages that depend on NetPro.Startup:
Package | Downloads |
---|---|
NetPro.Core
Package Description |
|
NetPro.Checker
for checking the complex environment of application in the microservice environment. provide the system environment information of the current application. and Checking the health of application information and components |
|
NetPro.Web.Api
Package Description |
|
NetPro.NetProShareRequestBody
Package Description |
|
NetPro.MongoDb
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
6.0.16 | 1,135 | 7/24/2023 |
6.0.15 | 5,598 | 7/19/2022 |
6.0.14 | 5,150 | 7/10/2022 |
6.0.13 | 5,357 | 6/15/2022 |
6.0.12 | 5,264 | 6/15/2022 |
6.0.11 | 5,181 | 6/15/2022 |
6.0.10 | 5,139 | 6/11/2022 |
6.0.9 | 5,299 | 6/8/2022 |
6.0.8 | 5,007 | 5/26/2022 |
6.0.8-beta.3 | 504 | 5/24/2022 |
6.0.8-beta.2 | 130 | 5/24/2022 |
6.0.7 | 5,098 | 5/18/2022 |
6.0.6 | 4,814 | 4/28/2022 |
6.0.5 | 4,998 | 3/30/2022 |
6.0.5-beta.20 | 121 | 4/27/2022 |
6.0.5-beta.19 | 129 | 4/25/2022 |
6.0.5-beta.18 | 127 | 4/22/2022 |
6.0.5-beta.17 | 140 | 4/16/2022 |
6.0.5-beta.16 | 582 | 4/8/2022 |
6.0.5-beta.15 | 125 | 4/8/2022 |
6.0.5-beta.14 | 141 | 4/7/2022 |
6.0.5-beta.13 | 140 | 4/7/2022 |
6.0.5-beta.12 | 132 | 4/6/2022 |
6.0.5-beta.11 | 155 | 4/6/2022 |
6.0.5-beta.10 | 153 | 3/31/2022 |
6.0.5-beta.9 | 211 | 3/26/2022 |
6.0.5-beta.8 | 161 | 3/22/2022 |
6.0.5-beta.7 | 137 | 3/21/2022 |
6.0.5-beta.6 | 164 | 3/14/2022 |
6.0.5-beta.5 | 157 | 3/2/2022 |
6.0.5-beta.4 | 163 | 2/22/2022 |
6.0.5-beta.3 | 151 | 2/18/2022 |
6.0.5-beta.2 | 141 | 2/18/2022 |
6.0.5-beta.1 | 168 | 2/16/2022 |
6.0.4 | 3,052 | 2/10/2022 |
6.0.3 | 2,696 | 2/9/2022 |
6.0.3-beta.9 | 129 | 2/10/2022 |
6.0.3-beta.7 | 156 | 1/27/2022 |
6.0.3-beta.6 | 159 | 1/19/2022 |
6.0.3-beta.5 | 160 | 1/17/2022 |
6.0.3-beta.4 | 150 | 1/16/2022 |
6.0.3-beta.3 | 143 | 1/14/2022 |
6.0.3-beta.2 | 151 | 1/13/2022 |
6.0.3-beta.1 | 168 | 1/11/2022 |
6.0.2 | 1,383 | 1/6/2022 |
6.0.1 | 2,176 | 12/3/2021 |
3.1.11 | 1,794 | 11/19/2021 |
3.1.10 | 375 | 11/17/2021 |