2016-01-22 77 views
2

在ASP.NET 5的beta 8中,我可以訪問CallContextServiceLocator。這在RC1中不再可用。什麼替換CallContextServiceLocator?

如何在下面的代碼中將呼叫替換爲CallContextServiceLocator。我正在使用該代碼來創建服務的測試實例。

private static TestServer CreateTestServer(HttpMessageHandler backchannelHttpHandler = null) 
    { 
     HostingEnvironment hostingEnvironment = new HostingEnvironment { EnvironmentName = "Testing", }; 
     Microsoft.Extensions.PlatformAbstractions.IApplicationEnvironment appEnv = 
      CallContextServiceLocator.Locator.ServiceProvider.GetRequiredService<Microsoft.Extensions.PlatformAbstractions.IApplicationEnvironment>(); 

     Startup serviceStartup = new Startup(hostingEnvironment, appEnv, backchannelHttpHandler); 

     Action<IApplicationBuilder> configureApp = app => serviceStartup.Configure(app, appEnv, new LoggerFactory()); 
     Action<IServiceCollection> configureServices = svc => serviceStartup.ConfigureServices(svc); 

     WebApplicationBuilder webAppBuilder = new WebApplicationBuilder(); 
     webAppBuilder.Configure(configureApp); 
     webAppBuilder.ConfigureServices(configureServices); 

     return new TestServer(webAppBuilder); 
    } 

回答

2

PlatformServices.Default有沒有替代本身,它死了埋RIP :)。您可以使用平臺服務獲取特定組件。此外,託管API已被修改爲不太爛,所以默認情況下不需要任何東西傳入它。

1

替換爲Microsoft.Extensions.PlatformAbstractions