• Apollo 与 .net core


    appsettings配置内容

    {
      "Apollo": {
        "AppId": "netcore",
        "Env": "dev",
        "Cluster": "default",
        "Meta": {
          "Dev": "http://10.2.2.139:8080/",
          "Pro": "http://10.2.2.140:8080/"
        }
      }
    }

    Program.cs

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Threading.Tasks;
    using Com.Ctrip.Framework.Apollo;
    using Com.Ctrip.Framework.Apollo.Enums;
    using Com.Ctrip.Framework.Apollo.Logging;
    using Microsoft.AspNetCore;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.Logging;
    
    
    namespace apollo.test
    {
        public class Program
        {
            public static void Main(string[] args)
            {
                Com.Ctrip.Framework.Apollo.Logging.LogManager.UseConsoleLogging(Com.Ctrip.Framework.Apollo.Logging.LogLevel.Trace);
                //Com.Ctrip.Framework.Apollo.Logging.LogManager.Provider = new ConsoleLoggerProvider(Com.Ctrip.Framework.Apollo.Logging.LogLevel.Trace);
                BuildWebHost(args).Run();
            }
    
            public static IWebHost BuildWebHost(string[] args) =>
                WebHost.CreateDefaultBuilder(args)
                    .ConfigureAppConfiguration((hostingContext, builder) =>
                    {
                        builder
                        .AddApollo(builder.Build().GetSection("apollo"))
                        .AddDefault();
                    })
                    .UseStartup<Startup>()
                    .Build();
        }
    }

    读取配置

    using System.Collections.Generic;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.Extensions.Configuration;
    
    namespace apollo.test.Controllers
    {
        //,
        //"ConfigServer": [ "http://10.228.1.107:8080/" ]
        [Route("api/[controller]")]
        [ApiController]
        public class ValuesController : ControllerBase
        {
            IConfiguration _configuration;
            public ValuesController(IConfiguration configuration)
            {
                _configuration = configuration;
            }
            // GET api/values
            [HttpGet]
            public ActionResult<IEnumerable<string>> Get()
            {
                return new string[] {  _configuration["env"] };
            }
        }
    }
  • 相关阅读:
    老外写的js闭包
    List<Object> 转为 List<MyClass>
    html 自定义属性
    js 中的算术运算
    System.Web.Mvc.Html 命名空间小计
    历时半年,发布最完整的代码生成器CodeBuilder最新版本
    CodeBuilder之Template接口
    CodeBuilder之Tool接口
    FaibClass.Data
    轻量的Json序列化
  • 原文地址:https://www.cnblogs.com/chenyishi/p/11113663.html
Copyright © 2020-2023  润新知