Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What replaces CallContextServiceLocator?

Tags:

asp.net-core

In the beta 8 of ASP.NET 5, I had access to the CallContextServiceLocator. This is no longer available in the RC1.

How can I replace the call to CallContextServiceLocator in the following code below. I am using that code to create test instance of the service.

    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);
    }
like image 392
Martin Avatar asked Dec 03 '25 22:12

Martin


1 Answers

There's no replacement per se, it's dead gone buried RIP :). You can use platform services to get specific components. Also the hosting API has been revamped to be less sucky so it doesn't require anything to be passed into it by default.

like image 183
davidfowl Avatar answered Dec 05 '25 15:12

davidfowl