如何在 C# Windows 服务应用程序中使用 PRISM?
我正在尝试创建一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
锁定此。您可以下载示例,如图所示。
下载并安装 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 namedservice
.This is simple, you can call Wcf-service in these method right here.(also you can use wcf method as async-service )