2011-05-14 160 views
2

我想创建一个Windows服务应用程序,我可以在其中添加模块,就像我们在WPF和Silverlight中一样。 这是我如何去扔:如何在C#windows服务应用程序中使用PRISM?

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); 
    }   
} 

是否有出有什么样?

+0

这些片段似乎是好的。你错过了什么?我唯一要做的就是删除'new MyService'并让棱镜解决这个问题 - 使用'Container'属性和'Resolve '来让你的服务具有所有的依赖关系。 – 2011-05-15 12:32:45

+0

您能够让您的服务运行吗?我还没有成功,我在我的服务中使用EventAggregator和Unity。 – grefly 2011-08-05 07:39:05

+0

这方面的更新? – 2014-01-14 16:45:35

回答

1

锁定在this。你可以下载那里的样本,你可以看到图片

下载并安装prism(v4)后,在根目录下你有一个名为stock trader的文件夹。这就是你需要的! (运行桌面版)。在章节模块中,您可以找到名为service的文件夹。

这很简单,你可以在这些方法就在这里调用WCF服务。(你也可以使用WCF方法异步服务)

+0

Hi Rev,链接给了Silverlight和Windows桌面的很多示例,但没有提供棱镜的Windows服务示例。 – 2011-05-15 06:42:26

相关问题