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

发布于 2024-11-07 10:19:58 字数 1228 浏览 1 评论 0原文

我正在尝试创建一个 Windows 服务应用程序,我可以像在 WPF 和 Silverlight 中一样在其中添加模块。 这就是我抛出的方式:

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

有任何示例吗?

I'm trying to create an windows service application which i would be able to add modules in it as we do in WPF and Silverlight.
This is how i went 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();
    }    
}

And for the ShellBootstrapper class :

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

Are there any sample out there?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

败给现实 2024-11-14 10:19:58

锁定。您可以下载示例,如图所示。

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

这很简单,你可以在这些方法中调用 Wcf-service 。(也可以使用 wcf 方法作为 async-service )

lock at this. you can download there sample as you can see in picture

After download and installing prism(v4), in root directory you have folder named as stock trader. that's what you need! (run desktop version). In section Modules you can Find folder named service.

This is simple, you can call Wcf-service in these method right here.(also you can use wcf method as async-service )

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文