我正在尝试创建一个 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);
}
}
那里有样品吗?