tôi có một app.configLàm thế nào để có được tên cửa sổ dịch vụ từ app.config
<appSettings>
<add key="ServiceName" value="HasService"/>
<add key="ServiceDisplayName" value="HasService"/>
</appSettings>
lớp dịch vụ cài đặt của tôi
[RunInstaller(true)]
public class MyServiceInstaller : System.Configuration.Install.Installer
{
public MyServiceInstaller()
{
var process = new ServiceProcessInstaller {Account = ServiceAccount.LocalSystem};
var serviceAdmin = new ServiceInstaller
{
StartType = ServiceStartMode.Manual,
ServiceName = "HasService",
DisplayName = "HasService"
};
Installers.Add(process);
Installers.Add(serviceAdmin);
}
}
tôi muốn có được tên dịch vụ từ app.config.
var serviceAdmin = new ServiceInstaller
{
StartType = ServiceStartMode.Manual,
ServiceName = GetServiceNameAppConfig("ServiceName"),
DisplayName = GetServiceNameAppConfig("ServiceDisplayName")
};
public string GetServiceNameAppConfig(string serviceName)
{
//what should i write here?
}
cách nhận tên dịch vụ và tên hiển thị dịch vụ từ tệp app.config trong lớp MyServiceInstaller.
lý do tại sao bạn sẽ muốn làm điều này? Tôi có thể thấy một lý lẽ cho việc đưa "những thứ có thể thay đổi một ngày" vào tập tin cấu hình, nhưng bạn sẽ nghiêm túc đặt tên của một dịch vụ trong thể loại này? Ngoài ra, bạn có thể thay đổi tệp cấu hình nhiều như bạn muốn, nhưng trừ khi bạn cài đặt lại dịch vụ (tức là trừ khi MsServiceInstaller thực hiện công cụ của nó), bạn sẽ không thực sự thay đổi tên dịch vụ. Điều này có khả năng có thể gây nhầm lẫn cho một người nào đó phải duy trì. – PeteH
@Pete tôi muốn chạy dịch vụ với hai tên khác nhau. – sinanakyazici
@sinanakyazici Nó làm việc cho tôi! Cảm ơn rất nhiều –