使用新框架与技术代替旧框架与技术,实现涂装车间后道标签扫码程序
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using RIZO_Application.Infrastructure.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace RIZO_Application.Infrastructure.AppConfig
|
||||
{
|
||||
public static class AppConfig
|
||||
{
|
||||
public static IConfiguration Configuration { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 静态构造函数,非常适合用于初始化
|
||||
/// </summary>
|
||||
static AppConfig()
|
||||
{
|
||||
//var builder = new ConfigurationBuilder()
|
||||
// .SetBasePath(Directory.GetCurrentDirectory())
|
||||
// .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
||||
|
||||
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production";
|
||||
|
||||
var builder = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{environment}.json", optional: true);
|
||||
|
||||
Configuration = builder.Build();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static T GetSection<T>(string sectionName) where T : class, new()
|
||||
{
|
||||
var section = new T();
|
||||
Configuration.GetSection(sectionName).Bind(section);
|
||||
return section;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user