반응형
ConfigureServices 메서드에서 IHostingEnvironment 액세스
ConfigureServices
현재 호스팅 환경 이름이 '개발'인지 확인해야합니다 .
그래서 IHostingEnvironment.IsDevelopment()
방법을 사용 하는 것은 나에게 괜찮을 수 있지만 Configure 방법과 달리 IHostingEnvironment env
.
IHostingEnvironment를 유지하려면 Startup 클래스에 속성을 만듭니다. 이미 액세스 권한이있는 Startup 생성자에서 속성을 설정 한 다음 ConfigureServices에서 속성에 액세스 할 수 있습니다.
이 질문 과 중복 된 것으로 표시된 질문에서 여기로 복사 하여 삭제했습니다 . 배우 에 대한 크레딧 .
액세스하려는 경우 IHostingEnvironment
에 ConfigureServices
사용하면 생성자를 통해 주입과에서 나중에 액세스를 위해 보관해야합니다 ConfigureServices
:
public class Startup
{
public Startup(IConfiguration configuration, IHostingEnvironment environment)
{
Configuration = configuration;
Environment = environment;
}
public IConfiguration Configuration { get; }
public IHostingEnvironment Environment { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
System.Console.WriteLine($"app: {environment.ApplicationName}");
}
// rest omitted
}
반응형
'your programing' 카테고리의 다른 글
신호 처리기에서 printf를 사용하지 않는 방법은 무엇입니까? (0) | 2020.10.12 |
---|---|
Laravel의 Artisan을 설치하는 방법은 무엇입니까? (0) | 2020.10.12 |
MSIL과 Java 바이트 코드의 차이점은 무엇입니까? (0) | 2020.10.12 |
SQL의 데이터베이스 테이블에서 상위 n 개를 제외한 모두 삭제 (0) | 2020.10.12 |
C ++에서 big int를 구현하는 방법 (0) | 2020.10.12 |