在ASP.NET 5的beta 8中,我可以访问CallContextServiceLocator。 RC1中不再提供此功能。
如何在以下代码中替换对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);
}
答案 0 :(得分:3)
替换为PlatformServices.Default
来自Microsoft.Extensions.PlatformAbstractions
答案 1 :(得分:3)
本身没有任何替代品,它已经死了RIP :)。您可以使用平台服务来获取特定组件。此外,托管API已经被修改为不那么糟糕,因此默认情况下它不需要传递任何内容。