如何查看是否在服务结构下运行
我有时在Visual Studio中本地运行项目是否有更好的方法来检测我是否由SF托管而不是exception。 我可以看到路径或入口组件,但必须有更好的方法。
try { ServiceRuntime.RegisterServiceAsync("FisConfigUIType", context = > new WebHost (context, loggerFactory, "ServiceEndpoint", Startup.serviceName)).GetAwaiter().GetResult(); Thread.Sleep(Timeout.Infinite); } catch (FabricException sfEx) { RunLocal(args, loggerFactory); }
检查服务结构环境变量 :
var sfAppName = Environment.GetEnvironmentVariable("Fabric_ApplicationName"); var isSf = sfAppName != null;
来源:来自@mkosieradzki GitHub Issue
这就是我提出的,但没有例外的东西会更好(并注意一些项目使用Core)
static bool IsSFHosted() { try { FabricRuntime.GetNodeContext(); return true; } catch (FabricException sfEx) when (sfEx.HResult == -2147017661 || sfEx.HResult == -2147017536 || sfEx.InnerException?.HResult == -2147017536) { return false; } }
例如。
上述就是C#学习教程:如何查看是否在服务结构下运行分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
var isSFHosted = IsSFHosted(); var servicesPreRegister = builder.GetPreRegisterServicesForStore(node: node, security: false); if (isSFHosted) { ServiceRuntime.RegisterServiceAsync("DeliveriesWriteType", context => new WebAPI(context, loggerFactory, servicesPreRegister)).GetAwaiter().GetResult(); } else { loggerFactory.AddConsole(); // run with local web listener with out SF }
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1014048.html