I'm migrating an Asp.net Core 2.0 app hosted in Service Fabric to Asp.net Core 2.1. Service Fabric does not have yet a template for Asp.net Core 2.1, so I followed the official tutorial here, but was not able to do the changes to "Program.cs" file, in particular in a non SF hosted app:
namespace WebApp1
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
}
while in Service Fabric
namespace Web1
{
internal sealed class Web1 : StatelessService
{
public Web1(StatelessServiceContext context)
: base(context)
{ }
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new ServiceInstanceListener[]
{
new ServiceInstanceListener(serviceContext =>
new KestrelCommunicationListener(serviceContext, "ServiceEndpoint", (url, listener) =>
{
ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}");
return new WebHostBuilder()
.UseKestrel()
.ConfigureServices(
services => services
.AddSingleton<StatelessServiceContext>(serviceContext))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseUrls(url)
.Build();
}))
};
}
}
}
Without calling WebHost.CreateDefaultBuilder(args) the Host filering does not work as specified here
How do I make it work? Is it too soon to migrate to 2.1 for Service Fabric?
WebHost.CreateDefaultBuilder().ConfigureServices(...).UseStartup<Startup>().UseServiceFabricIntergration(...).UseUrls(...).Build()
. In case command line args are required you can pass them in ctor ofWeb1
class fromMain(...)
. – Oleg Karasik