我想創建一個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