. NET core uses Apollo for unified configuration Management

Source: Internet
Author: User
Tags webhost

Doing development for so many years, often due to configuration problems caused by the production environment bug. Some years long project, hundreds of dense configuration items, often easy to confuse, sometimes several projects have a lot of the same configuration items, configuration work is also a bother. Fortunately, Ctrip opens up a new generation of configuration center-the Apollo Project, which has recently been used for some time in the project, and it feels really convenient.

First, the local Apollo, please refer to the official website information Https://github.com/ctripcorp/apollo/wiki/Quick-Start.

Enter the management UI for Apollo and create the project:

  

Once the project is created, you can add key and value to the project:

  

After you add a key, you need to publish to take effect.

Add a Com.Ctrip.Framework.Apollo.Configuration NuGet package to a. NET Core project (is it written by a Java programmer?). ), modify the Program.cs file and the Appsettings.json file, Appsettings.json file AppID corresponds to the application in the above Id,metaserver address of the Euraka of Apollo:

  

 public  static  iwebhost buildwebhost ( string  [] args) => Webhost.createdefaultbuilder (args).                    Configureappconfiguration (Hostingcontext, builder)  => { Builder. Addapollo (builder. Build (). GetSection (  " apollo  "   <startup> (). Build ();  
{  "Apollo": {    "AppId": "SampleApp",    "metaserver": "/HTTP/ 192.168.2.168:8080 "  }}


This makes it easy to read the configuration items in Apollo in the project.

What if there are some public configuration items that need to be referenced by several projects? Namespace shines! Portal: The "Namespace" of the Apollo core concept

The configuration items that create pulic types of namespace,namespace are visible to each project, and the only thing you need to do is to publish the configuration items in the namespace in a project, and you need to change the Program.cs code again:

         Public StaticIwebhost Buildwebhost (string[] args) =Webhost.createdefaultbuilder (args). Configureappconfiguration (Hostingcontext, builder)={Builder. Addapollo (builder. Build (). GetSection ("Apollo"))                    . Adddefault (). AddNamespace ("Common");//the name of namespace in Apollo                })                . Usestartup<Startup>()                . Build ();

. NET core uses Apollo for unified configuration Management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.