尘叶心繁

.net core mvc中其他类库获取appsettings.json

电脑版发表于:2019/7/26 13:23

appsetting:

{
  "ApplicationSettings": {
    "DalAssemblyName": "INGEFDal"
  },
  ...
}

c#:

 public StaticDalFactory()
        {
            IConfigurationBuilder builder = new ConfigurationBuilder();
            builder.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"));

            var root = builder.Build();
            //这里将获取到INGEFDal
            var sampleConnectionString = root["ApplicationSettings:DalAssemblyName"];
            assemblyname = sampleConnectionString;
        }

前提是需要引用其他的库


更多获取方式请参考

https://stackoverflow.com/questions/38398022/access-from-class-library-to-appsetting-json-in-asp-net-core

这些大佬们的讨论

关于TNBLOG
TNBLOG,技术分享。技术交流:群号677373950
ICP备案 :渝ICP备18016597号-1
App store Android
精彩评论
{{item.replyName}}
{{item.content}}
{{item.time}}
{{subpj.replyName}}
@{{subpj.beReplyName}}{{subpj.content}}
{{subpj.time}}
猜你喜欢