-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Description
My application has code like below to set up an ASP.NET Core host using WebHost (.NET 8.0):
public class WCFServiceHost
{
private void SetupHttpWebHost(Uri[] baseAddresses)
{
var builder = Microsoft.AspNetCore.WebHost.CreateDefaultBuilder()
.ConfigureServices(x => x.AddSingleton(this))
.UseStartup<Startup>();
builder.Build().RunAsync();
}
}
internal class Startup
{
public Startup(WCFServiceHost wcfServiceHost)
{
}
}
Since WebHost becomes obsolete in .NET 10, I try to convert it to using Host with the code like below:
public class WCFServiceHost
{
private void SetupHttpWebHost(Uri[] baseAddresses)
{
var builder = Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder()
.ConfigureServices(x => x.AddSingleton(this))
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
builder.Build().RunAsync();
}
}
However, the application is getting
System.InvalidOperationException : Unable to resolve service for type 'WCFServiceHost' while attempting to activate 'Startup'. error.
I appreciate if someone can provide guidance about the right way of using Microsoft.Extensions.Hosting.Host.
Metadata
Metadata
Assignees
Labels
area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions