When creating an ASP.NET Core app an environment variable called ASPNETCORE_ENVIRONMENT=Development
will be set for you and when debugging you will see that the
The answer from Duncan worked for me, but there is a small variation for me, maybe due to the version of ASP.NET Core and Service Fabric I use.
I need to override the method CreateServiceInstanceListeners
in my Web Stateless Service.
So that means I'll have this code:
protected override IEnumerable CreateServiceInstanceListeners()
{
return new ServiceInstanceListener[]
{
new ServiceInstanceListener(serviceContext =>
new WebListenerCommunicationListener(serviceContext, "ServiceEndpoint", (url, listener) =>
{
ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting WebListener on {url}");
var environment = FabricRuntime.GetActivationContext()
?.GetConfigurationPackageObject("Config")
?.Settings.Sections["Environment"]
?.Parameters["ASPNETCORE_ENVIRONMENT"]?.Value;
return new WebHostBuilder().UseWebListener()
.ConfigureServices(
services => services
.AddSingleton(serviceContext))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup()
.UseEnvironment(environment)
.UseApplicationInsights()
.UseUrls(url)
.Build();
}))
};
}
Of course, you need to set the ASPNETCORE_ENVIRONMENT
variable as explained by Duncan.