首页 > Windows开发 > 详细

配置Apollo阿波罗.net core 3.1 c#

时间:2021-04-29 22:30:24      阅读:111      评论:0      收藏:0      [点我收藏+]

直接上代码:


public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder .ConfigureAppConfiguration((hostingContext, builder) => { builder .AddApollo(builder.Build().GetSection("apollo")) .AddDefault() .AddNamespace("application"); }) .UseStartup<Startup>();

 

 

 

技术分享图片

 

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  "apollo": {
    "AppId": "SampleApp", //AppId
    "MetaServer": "http://192.168.136.129:8080", // Eureka地址
    "ConfigServer": [
      "http://192.168.136.129:8080" //// Eureka地址
    ]
  }
}

 

 

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System.Collections.Generic;

namespace WebApolloDemo.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ValuesController : Controller
    {

        private readonly IConfiguration _configuration;

        public ValuesController(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        // GET api/values
        [HttpGet]
        public ActionResult<IEnumerable<string>> Get()
        {
            var appName = _configuration["timeout"];
            var hjk = _configuration["zcc"];
            return new string[] { "value1", "value2", appName, hjk };
        }


    }
}

 

ok,这是web的配置。搭建好Apollo后。

 

 

 

技术分享图片

 

 

 

 这样就可以了,后期出细节图。

技术分享图片

 

配置Apollo阿波罗.net core 3.1 c#

原文:https://www.cnblogs.com/zhaocici/p/14719436.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!