我想创建一个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);
}
}
是否有出有什么样?
这些片段似乎是好的。你错过了什么?我唯一要做的就是删除'new MyService'并让棱镜解决这个问题 - 使用'Container'属性和'Resolve'来让你的服务具有所有的依赖关系。 –
2011-05-15 12:32:45
您能够让您的服务运行吗?我还没有成功,我在我的服务中使用EventAggregator和Unity。 – grefly 2011-08-05 07:39:05
这方面的更新? – 2014-01-14 16:45:35