我有一个不承载Web服务的无状态服务。它使用天蓝色队列进行通信。我正在尝试设置配置文件,我需要访问环境变量。
它没有启动主机,因此没有启动类。我希望能够获得环境名称...
$“ appsettings。{hostingEnvironment.EnvironmentName} .json”
是否可以获取托管环境,甚至只是环境名称变量?
private static void Main()
{
try
{
ServiceRuntime.RegisterServiceAsync("MyServiceType",
context => new MyService(context)).GetAwaiter().GetResult();
ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(MyService).Name);
Thread.Sleep(Timeout.Infinite);
}
catch (Exception e)
{
ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
throw;
}
}
internal sealed class MyService : StatelessService
{
public MyService(StatelessServiceContext context) : base(context)
{
}
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new ServiceInstanceListener[0];
}
protected override async Task RunAsync(CancellationToken cancellationToken)
{
...
}
}