- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我一直在努力让重组工作,但没有运气......我尝试了很多次和很多方法 - 没有运气......任何人都可以指出我的错误吗?我希望在将新的 .dll 放入插件目录后,发件人集合将自动重新填充新内容...
//exported classes
[Export(typeof(ISender))]
public class SMTP : ISender
{
public string Name
{
get { return "SMTP plugin"; }
}
public void Send(string msg)
{
}
}
[Export(typeof(ISender))]
public class Exchange : ISender
{
public string Name
{
get { return "Exchange plugin"; }
}
public void Send(string msg)
{
// .. blah
}
}
/-------------------------------------------- ------------------------
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private const string STR_Pugins = ".\\plugins";
[ImportMany(typeof(ISender), AllowRecomposition = true)]
private List<ISender> Senders;
private DirectoryCatalog d;
CompositionContainer c;
public MainWindow()
{
InitializeComponent();
listBox1.DisplayMemberPath = "Name";
ConfigPlugins();
bindSenders();
}
private void ConfigPlugins()
{
DirectoryInfo dir = new DirectoryInfo(STR_Pugins);
if (!dir.Exists)
dir.Create();
d = new DirectoryCatalog(STR_Pugins);
d.Changed += new EventHandler<ComposablePartCatalogChangeEventArgs>(d_Changed);
c = new CompositionContainer(d);
c.ExportsChanged += new EventHandler<ExportsChangeEventArgs>(c_ExportsChanged);
c.ComposeParts(this);
}
void d_Changed(object sender, ComposablePartCatalogChangeEventArgs e)
{
bindSenders();
MessageBox.Show("d_Changed " + (Senders == null ? 0 : Senders.Count));
}
private void bindSenders()
{
listBox1.ItemsSource = Senders;
}
void c_ExportsChanged(object sender, ExportsChangeEventArgs e)
{
bindSenders();
MessageBox.Show("c_ExportsChanged "+ (Senders == null ? 0 : Senders.Count));
}
}
public partial class MainWindow : Window
{
private const string STR_Pugins = ".\\plugins";
[ImportMany(typeof(ISender), AllowRecomposition = true)]
private List<ISender> Senders;
DirectoryCatalog d;
CompositionContainer c;
public MainWindow()
{
InitializeComponent();
listBox1.DisplayMemberPath = "Name";
ConfigPlugins();
bindSenders();
}
private void ConfigPlugins()
{
DirectoryInfo dir = new DirectoryInfo(STR_Pugins);
if (!dir.Exists)
dir.Create();
d = new DirectoryCatalog(STR_Pugins);
c = new CompositionContainer(d);
c.ComposeParts(this);
}
private void bindSenders()
{
label1.DataContext = Senders;
listBox1.ItemsSource = Senders;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
d.Refresh();
bindSenders();
}
}
最佳答案
你必须调用Refresh你自己。如果你愿意,你可以使用 FileSystemWatcher对象在目录内容更改时得到通知。
关于c# - mef - 如何自动进行重组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4186156/
我有此消息的CompositionException异常: “类型为'SomeService'的ComposablePart不能重新组合,因为它处于无效状态。只有在已经完全预览或组合的情况下,才可以重
我目前正在调查 MEF,以了解我们公司正在编写的软件的某种插件子系统的可行性。我想到的第一个问题是了解 MEF 组件对应用程序加载时间的影响。 此外,如果这很重要,是否有可能在运行时完全加载这些组件?
我开始学习,MEF 和其中一件重要的事情是我可以用导出属性标记一些项目(类、属性、方法),以便任何想要使用它的人都会在实例变量上创建导入属性并使用它。这种映射是如何发生的,何时发生?导入是按需延迟发生
我知道 MEF CompositionContainer 创建并保留类的实例。我不知道在什么情况下 CompositionContainer 在其内部有一个类实例。 任何人都可以列出在 Composi
我需要向我们现有的代码添加一些扩展点,并且我一直将 MEF 视为一种可能的解决方案。我们有一个 IRandomNumberGenerator 接口(interface),带有一个我们希望可交换的默认实
我看到 MEF ( MEF Codeplex site ) 上的新功能仍在继续工作,并且他们正在发布 MEF 2 beta 版本,但是他们没有关于新功能正在试验/探索/构建的任何体面的文档? 那么,作
我有一个对象实例,并且我希望最终得到一个包含该对象实例并导出为特定接口(interface)类型的 MEF 目录。我怎样才能做到这一点? TypeCatalog在这里似乎不起作用,因为(a)它创建一个
我计划在 ASP.NET 中使用 MEF,以深入了解 CompositionContainer 的线程安全性。 我的第一种方法将不同的 CompositionContainer 与每个请求相关联,但我
这类似于我的代码的外观 var catalog = new AssemblyCatalog(typeof(Program).Assembly); _container = new Compositio
我正在使用 MEF 和 System.ComponentModel.Composition.dll 来加载一些 dll。 我正在做类似的事情: AggregateCatalog catalog = n
我认识到,MEF 仅限于 metro 风格的应用程序。没有容器了,那么我怎样才能获得特定的导出值,如 ILogger logger = container.GetExportedValues(); ?
据我所知,为了使导入/导出属性相互正确连接,我必须对具有这些属性的每个新实例调用 compositionContainerInstance.Compose(...)。 是否可以自动发生这种情况,这样我
所以不使用 ExportMetadata 属性,为什么不直接扩展接口(interface)呢? 最佳答案 如果您通过 MEF 导入 Lazy<> 内容,则无需实例化对象即可查看元数据。 关于mef -
我正在尝试将 signalR 集线器作为使用 MEF 的插件的一部分。但是在 List<> 对象上调用 ImportMany 然后在 Global.asax 文件的 Application_Start
我找不到它!? 最佳答案 ExportFactory不是桌面 MEF 的一部分(但是 - 截至目前,它仅针对 Silverlight 发布)。看起来它将包含在 MEF 2 中。 与此同时,Glenn
安装包含 MEF 组件的 VSIX 项目时,Visual Studio 如何查找 MEF 组件?我知道常规方法可能是添加包含 MEF 部分的 dll 目录的目录。 Visual Studio 如何知道
是否可以将 IronPython 类声明为“导出”,从而将它们添加到 MEF 目录中主机 C# 应用程序可以导入吗? 我真的找不到任何具体的例子,只是猜测。 以下是我如何手动加载实现 .NET 接口(
MEF 团队一直在说它是关于插件模型的。那么,我们是在谈论 UI 插件吗?我们如何在非 UI 代码中使用这些东西? 我下载了代码,示例都是关于 GUI 的。我猜错了吗? 最佳答案 伊利亚 MEF 绝对
我有一个选项卡式应用程序,我希望用户能够在其中搜索某个人,然后在新 View 中显示此人的详细信息。用户应该能够为不同的人打开多个人的详细信息 View 。 我有点不确定我是否遵循了创建新 View
在 What's new in .NET 4.5微软表示 MEF 现在将支持“多范围”。这是什么意思?我在任何地方都找不到关于它的文档。 最佳答案 我相信你的问题在这个博客中得到了完整的回答:http
我是一名优秀的程序员,十分优秀!