ASP.NET Core Using Apollo

2023年9月11日 52点热度 0人点赞 0条评论
内容目录

Deploy Apollo and create an application.

file

Then create a namespace, select private to create a private namespace, and choose the json format.
file

Click modify text and fill in the json content.
file

Next, reference the package in the .NET program

        <PackageReference Include="Com.Ctrip.Framework.Apollo.Configuration" Version="2.10.2" />

Define the Apollo settings in the configuration file.

{
  "apollo": {
    "AppId": "ApolloTest",
    "MetaServer": "http://192.168.80.70:8080",
    "ConfigServer": "http://192.168.80.70:8080",
    "Env": "DEV",
    "Namespaces": [
      "DEV"
    ]
  },
  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "Microsoft.AspNetCore": "Debug"
    }
  },
  "AllowedHosts": "*"
}

Finally, inject it in the code:


var builder = WebApplication.CreateBuilder(args);
builder.Host.ConfigureAppConfiguration(b =>
{
    b.AddApollo(builder.Configuration.GetSection("apollo")).AddNamespace("DEV",ConfigFileFormat.Json);
});

痴者工良

高级程序员劝退师

文章评论