2014-10-31 92 views
3

「啓動參數」我已經添加命令行支持我topshelf程序如下:Windows服務的訪問從Topshelf

HostFactory.Run(hostConfigurator => 
{ 
    hostConfigurator.AddCommandLineDefinition("params", f => { startParams = f; });  
    hostConfigurator.ApplyCommandLine(); 
} 

這工作得很好。

當我安裝它作爲一個服務,我是在已安裝的服務,希望「啓動參數」,將達到同樣的目的,但事實並非如此。

誰能告訴我如何從TopShelf訪問「啓動參數」?

我希望通過啓動參數對同一服務的多次(具有不同的實例名稱),這是不同的安裝,我也想用它測試值通過。

我想只是簡單的訪問這些程序爲標準的服務可能會指出我在正確的方向。

謝謝。

+0

請參閱我的回答[here](http://stackoverflow.com/questions/15245770/how-to-specify-command-line-options-for-service-in-topshelf/36044058#36044058)我如何得到圍繞這個限制 – 2016-03-16 18:36:15

回答

1

相關服務的安裝參數,如服務名稱,描述,實例名稱等可以按如下

HostFactory.Run(x => 
{ 
    x.Service((ServiceConfigurator<MyService> s) => 
    { 
     s.ConstructUsing(settings => 
     { 
      var instanceName= settings.InstanceName; 
       return new MyService(); 
     }); 
    } 
} 

訪問,或者如果你的MyService實現的ServiceControl

 HostFactory.Run(x => 
     { 
      x.Service<MyService>((s) => 
      { 
       var instanceName= s.InstanceName; 

       return new MyService(); 
      }); 
     } 
/***************************/ 

class MyService : ServiceControl 
{ 
    public bool Start(HostControl hostControl) { } 

    public bool Stop(HostControl hostControl) { } 
} 

我不知道是什麼你的意思是「開始參數」,如果以上不是你想要的,試着用僞代碼示例來解釋你試圖達到的目標。