Skip to content

ASP.NET Core & Apollo

Apollo 是携程开源的一款开源配置中心。Apollo 对 Java 的支持比较好,.NET 中使用灵活性差了好多。

使用方法

  1. 安装 NuGet - Com.Ctrip.Framework.Apollo.Configuration

    powershell
    Install-Package Com.Ctrip.Framework.Apollo.Configuration
  2. appsettings.json 中添加 apollo 配置。

    json
    {
      "apollo": {
    	"AppId": "SampleApp",
    	"MetaServer": "http://192.168.2.168:8080"
      }
    }
  3. 修改 Program.csCreateWebHostBuilder 方法

    csharp
    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    	WebHost.CreateDefaultBuilder(args)
    		.ConfigureAppConfiguration((hostingContext, builder) =>
    		{
    			builder
    			.AddApollo(builder.Build().GetSection("apollo"))
    			.AddDefault();
    			//.AddNamespace("Common");//Apollo中NameSpace的名称
    		})
    		.UseStartup<Startup>();
  4. Startup.cs 通过 Configuration 属性获取配置。

    csharp
    string connectionString = Configuration["ConnectionString"];

安装 Com.Ctrip.Framework.Apollo.Configuration 失败

正在还原 D:\liujiajia\Source\gitee\OctopusCloudTeamService\CotopusCloudConfig\CotopusCloudConfig.csproj 的包...
NU1107: 检测到 Microsoft.Extensions.Configuration 存在版本冲突。直接从项目引用包可解决此问题。
CotopusCloudConfig -> Com.Ctrip.Framework.Apollo.Configuration 1.4.0 -> Microsoft.Extensions.Configuration.Binder 2.1.1 -> Microsoft.Extensions.Configuration (>= 2.1.1)
CotopusCloudConfig -> Microsoft.AspNetCore.App 2.1.0 -> Microsoft.Extensions.Configuration (= 2.1.0).
程序包还原失败。正在回滚“CotopusCloudConfig”的程序包更改。
已用时间: 00:00:00.9765635
========== 已完成 ==========

这个是由于我的 VS 2017 版本较旧,.NET Core 版本是 2.1.0 导致的。至少需要升级到 2.1.1 。
最新的 .NET SKD 可以从这里 => .NET SDKs for Visual Studio 下载。

或者通过 -version 指定安装的版本

powershell
Install-Package Com.Ctrip.Framework.Apollo.Configuration -version 1.3.1

1.4.0 的依赖项

  • .NETStandard,Version=v2.0
  • Com.Ctrip.Framework.Apollo (>= 1.4.0)
  • Microsoft.Extensions.Configuration.Binder (>= 2.1.1)

1.3.1 的依赖项

  • .NETStandard,Version=v2.0
  • Com.Ctrip.Framework.Apollo (>= 1.3.1)
  • Microsoft.Extensions.Configuration.Binder (>= 2.0.0)

参考

  1. .net core使用Apollo做统一配置管理
  2. NuGet - Com.Ctrip.Framework.Apollo.Configuration
  3. Apollo开发指南
  4. apollo.net core
  5. .NET SDKs for Visual Studio

Page Layout Max Width

Adjust the exact value of the page width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the page layout
A ranged slider for user to choose and customize their desired width of the maximum width of the page layout can go.

Content Layout Max Width

Adjust the exact value of the document content width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the content layout
A ranged slider for user to choose and customize their desired width of the maximum width of the content layout can go.