2017-09-12 19 views
-1

我有5個服務結構無狀態服務。我必須根據每個文件的部分名稱在類庫中獲取這些服務結構settings.xml值。我將創建一個公共類,它將以SectionName作爲參數,並且必須獲取所有配置值。如何獲取服務結構項目設置.xml值

回答

0

您可以使用此作爲起點:

internal sealed class YourService: StatelessService 
{ 
    public YourService(StatelessServiceContext context) 
     : base(context) 
    { 
     var configurationPackage = Context.CodePackageActivationContext.GetConfigurationPackageObject("Config"); 
     var sectionParams = configurationPackage.Settings.Sections["sectionname"].Parameters; 
     // You can now iterate through these parameters (e.g. get count and access by index) 
     //sectionParams.Count; 
     //sectionParams[0].Name; 
     //sectionParams[0].Value; 

我不知道是否有一個圖書館找到其他服務的ServiceContext的方式。請注意,並非所有服務都可能部署到相同的節點。這可能會影響配置可用性。

您可能需要創建一箇中心服務或參與者來收集所有其他服務的配置值。