c# – 如何获取当前Service Fabric应用程序名称?
发布时间:2020-12-15 23:37:01 所属栏目:百科 来源:网络整理
导读:是否可以获取运行我的代码的Service Fabric应用程序的名称? 例如,我的ApplicationParameters文件包含: Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="fabric:/mytestapp" xmlns
是否可以获取运行我的代码的Service Fabric应用程序的名称?
例如,我的ApplicationParameters文件包含: <Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="fabric:/mytestapp" xmlns="http://schemas.microsoft.com/2011/01/fabric"> 我想检索“mytestapp”并在我的代码中使用它,但我没有找到任何可以让我这样做的东西.有任何想法吗? 解决方法
ApplicationName作为字符串(不幸的是不是URI)作为CodePackageActivationContext上的属性存在.
// System.Fabric.CodePackageActivationContext public string ApplicationName { get; internal set; } CodePackageActivationContext存在于ServiceContext上,每个服务都在其构造函数中传递.有状态服务的示例. public StatefulService(StatefulServiceContext serviceContext) : this(serviceContext,new ReliableStateManager(serviceContext,null)) { } 如果您的服务是访客或容器或不使用ReliableServices API的东西,那么明确地将名称作为配置设置传递可能是您最好的选择. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |