c# - 如何在 C# Windows 服务应用程序中使用 PRISM?

标签 c# windows-services prism prism-4

我正在尝试创建一个 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/

相关文章:

c# - NET 6.0应用程序: Serilog exception on startup when trying to log to Azure Application Insights

c# - 查询 LDAP

wcf - 将 Silverlight 客户端与服务引用生成的类解耦

c# - 如何从 WCF 服务应用程序获取客户端地址?

mvvm - 如何使用 MVVM、PRISM 和 MEF 在没有用户请求的情况下处理来自 View 模型的 UI 交互

xamarin - Xamarin Prism无法导航到LoginPageViewModel

c# - 如何在 RavenDB 中的对象集合中搜索 "Not Contains"条件

c# - 使用 Azure WebJobs SDK 进行依赖注入(inject)?

.net-3.5 - WCF 服务与 Windows 服务

c# - Windows 服务异常处理和计时器