运行目录的所有模块(棱镜)
我正在使用棱镜的桌面库。
我想要的是在目录中获取模块,然后运行它们。
我确实喜欢这样:
DirectoryModuleCatalog catalog = new DirectoryModuleCatalog();
catalog.ModulePath = @"C:\Users\Raph\Documents\Visual Studio 2010\Projects\LibraryLoad\LibraryLoad\Modules";
我检查过,模块已加载到目录中。 模块示例:
public class SendEmailClass : IModule
{
public void SendEmail()
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("**", "moi");
mail.Subject = "Report"; //manage generated subject
mail.To.Add("***");
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
smtp.Port = 57;
smtp.EnableSsl = true; //depending of the smtp server
NetworkCredential cred = new NetworkCredential("***", "***");
smtp.Credentials = cred;
smtp.Send(mail);
}
public void Initialize()
{
SendEmail();
}
}
但是我想运行它们(启动它们的 Initialize()),但我找不到它。我想运行整个目录。有人有主意吗?我尝试过catalog.Initialize(),catalog.Validate()或catalog.Load()
i'm using the desktop library of prism.
what i want is to get modules in a directory and then, run them.
I do like that:
DirectoryModuleCatalog catalog = new DirectoryModuleCatalog();
catalog.ModulePath = @"C:\Users\Raph\Documents\Visual Studio 2010\Projects\LibraryLoad\LibraryLoad\Modules";
I checked, the modules are loaded in the catalog.
Example of a module:
public class SendEmailClass : IModule
{
public void SendEmail()
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("**", "moi");
mail.Subject = "Report"; //manage generated subject
mail.To.Add("***");
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
smtp.Port = 57;
smtp.EnableSsl = true; //depending of the smtp server
NetworkCredential cred = new NetworkCredential("***", "***");
smtp.Credentials = cred;
smtp.Send(mail);
}
public void Initialize()
{
SendEmail();
}
}
But then i want to run them (launch their Initialize()) but i don't find it. I want to run the whole catalog. someone has an idea ? I tried catalog.Initialize(), catalog.Validate() or catalog.Load()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的代码看起来正确,我的印象是您必须重写
Bootstrapper
类中的GetModuleCatalog()
方法才能执行此操作。这是一个非常简单的Bootstrapper
的工作示例,它从模块目录加载模块。更新
可能不使用引导程序并加载模块,但我不明白为什么你不利用
UnityBootstrapper
类,它的工作是你。您的模块将被加载。我自己从来没有在不使用引导程序的情况下这样做过,因为它非常简单。
Your code looks correct, I was under the impression that you had to override the
GetModuleCatalog()
method in yourBootstrapper
class in order to do this. Here is a working example of a pretty straight forwardBootstrapper
that loads modules from a modules directory.Update
It is probably possible to not use a bootstrapper and load your modules, but I do not see why you would not take advantage of the
UnityBootstrapper
class, it does the work for you.Your modules will be loaded. I myself have never done this without using the bootstrapper because it is very straightforward.
正如 jsmith 所说,默认引导程序为您自己执行的配置提供了繁重的工作。如果您没有 Shell,只需创建一个跳过该部分的自定义引导程序即可。
如果您不想以任何方式使用引导程序,您可以实例化 ModuleManager 类,将 ModulesCatalog 作为参数之一传递并调用 ModuleManager 的 运行方法。
正如我之前所说,上面的操作是由 bootstrapper 为您完成的。
我希望这有帮助。
谢谢,
达米安
As jsmith said, the default bootstrapper provides the heavy lifting for the configuration that you would otherwise perform yourself. If you don't have a Shell, simply create a custom bootstrapper that skips over that part.
In case you don't want to use a bootstrapper by any means, you can just instantiate the ModuleManager class, passing the ModulesCatalog as one of the parameters and call the ModuleManager's Run method.
As I said before, the above is done by the bootstrapper for you.
I hope this helps.
Thanks,
Damian
您如何引导您的应用程序?您创建了引导程序类吗?它是初始化所有模块的引导程序。
这是我制作的引导程序类的示例。
然后,在
App.xaml
文件的OnStartup
中,运行引导程序,它将在所有模块上调用初始化。此示例使用 Unity 引导程序,您需要的只是 Unity 平台,该平台可与 < a href="http://compositewpf.codeplex.com/" rel="nofollow">棱镜。
How are you bootstrapping your application? Have you created a bootstrapper class? It is the bootstrapper that initializes all of your modules.
This is an example of a bootstrapper class I made.
Then in your
App.xaml
file'sOnStartup
, you run your bootstrapper and it will call initialize on all of your modules.This example uses the Unity bootstrapper, all you need is the Unity platform which is available side-by-side with Prism.