2017-11-10 4 views
0

웹 API를 호스팅하는 콘솔 응용 프로그램이 있습니다. 이제 이미 구성한 IServiceCollectionILoggerFactory을 내 Startup에 전달하려고합니다..NET Core 2에서 기존 IServiceCollection 및 ILoggerFactory를 시작으로 전환

var serviceCollection = new ServiceCollection(); 
// Do some registrations here... 

var loggerFactory = new LoggerFactory(); // Actually not created this way. Just an example. 
loggerFactory.AddSomeStuff(); 

var host = WebHost.CreateDefaultBuilder() 
    .UseKestrel() 
    .ConfigureServices(collection => 
    { 
     // I want to use my already configured serviceCollection. 
     // I do not want to configure it here... 
    }) 
    .ConfigureLogging((hostingContext, logging) => 
    { 
     // I want to use my already configured ILoggerFactory. 
     // I do not want to configure it here... 
    }) 
    .UseStartup<Startup>() 
    .Build(); 

은 기본적으로 내 시작 사용하려는 내 이미 loggerFactoryserviceCollection를 만들었습니다. 그게 가능하니? 그렇다면 어떻게해야합니까?

답변

0

WebHost의 Build 메서드는 메서드 변수로 ServiceCollection() 클래스의 인스턴스를 인스턴스화하고 있으며 모든 작업 대리자 (예 : ConfigureService(Action<IServiceCollection>configureService)))에게 전달됩니다. 자체 구현을 제외한 사용자 지정 메서드로 대체 할 방법이없는 것 같습니다. IWebHost (모든 종류의 문제를 소개 할 수 있음).