我正在尝试创建一个 Windows 服务应用程序,我可以像在 WPF 和 Silverlight 中那样在其中添加模块。 这就是我 throw 的方式:
public static class Program
{
public static string CurrentAppPath { get; set; }
static void Main()
{
Program.CurrentAppPath = Path.GetDirectoryName(
System.Reflection.Assembly.GetEntryAssembly().Location);
ShellBootstrapper bootstrapper = new ShellBootstrapper();
bootstrapper.Run();
}
}
对于 ShellBootstrapper 类:
class ShellBootstrapper : UnityBootstrapper
{
protected override IModuleCatalog CreateModuleCatalog()
{
DirectoryModuleCatalog directoryCatalog =
new DirectoryModuleCatalog() { ModulePath = Program.CurrentAppPath };
return directoryCatalog;
}
protected override System.Windows.DependencyObject CreateShell()
{
return null;
}
public override void Run(bool runWithDefaultConfiguration)
{
base.Run(runWithDefaultConfiguration);
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new MyService(logger)
};
ServiceBase.Run(ServicesToRun);
}
}
有 sample 吗?
最佳答案
锁定this .你可以在那里下载示例,如图所示
下载并安装 prism(v4) 后,在根目录中,您有一个名为 stock trader
的文件夹。这就是你需要的! (运行桌面版)。在模块部分,您可以找到名为 service
的文件夹。
这个很简单,你可以在这里调用这些方法中的Wcf-service。(你也可以使用wcf方法作为async-service)
关于c# - 如何在 C# Windows 服务应用程序中使用 PRISM?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6004190/