如何查看是否在服务结构下运行
我有时在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; } }
例如。
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 }
- 有状态服务的dependency injection
- 在Azure Service Fabric服务中实例化ServiceInitializationParameters的位置和方式是什么?
- 默认服务描述不能作为升级集EnableDefaultServicesUpgrade的一部分修改为true
- Microsoft Service Fabric主机服务(FabricHostSvc)挂起启动
- Service Fabric在启动时生成actor
- 如何使用tfs 2013与服务架构持续集成?
- 从Service Fabric WebAPI控制器写入ServiceEventSource
- Service Fabric包含其他文件
- 向在Service Fabric Cluster中的特定节点上运行的ASP.Net Core Web API发送请求