Azure에서 호스팅되는 ASP.NET Core 2 응용 프로그램이 있고 Azure 포털에서 내 응용 프로그램에 대한 새 응용 프로그램 설정 MyNewSetting
을 추가했습니다.컨트롤러에서 Azure AppSettings 가져 오기
컨트롤러에서 어떻게 해당 설정에 액세스합니까?
내 코드를 넣고 : 이public void ConfigureServices(IServiceCollection services)
{
services.AddOptions();
services.Configure<AppSecrets>(Configuration);
services.AddSingleton<ITableRepositories, TableClientOperationsService>();
//...
내 컨트롤러 : 여기
public class RecordController : Controller
{
const int MyNewSetting = 7; // this one to replace with Azure Setting one
private readonly ITableRepositories repository;
public RecordController(ITableRepositories rep) {
repository = rep;
}
, 나는 FromServices
주입을 추가 아마 필요하지만, 나는 그것이 작동하는지 모르겠습니다 ...
편집 :
Folowing @dee_zg의 대답은 다음과 같은 코드는 아마 일을 할 수있는 :
public class RecordController : Controller
{
int MyNewSetting = 7;
private readonly ITableRepositories repository;
public RecordController(ITableRepositories rep) {
repository = rep;
int myInt;
if (int.TryParse(System.Environment.GetEnvironmentVariable("MY_NEW_SETTING"),
out myInt)) {
MyNewSetting = myInt;
};
}
내 편집을 받아보실 수 있습니다. 많이 받았습니다. – Serge