在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);
}