ImportMany
MEF では、属性を使用して複数のパーツをインポートできます。関連するエクスポートを取得し、それらを入力している列挙型に追加する順序をどのように決定しますか? たとえば、特定の順序で起動する必要がある複数の IRule をインポートするにはどうすればよいでしょうか? 私が考えることができる唯一の方法は、IRule に OrderValue プロパティを設定し、手動で並べ替えることです。
public class Engine
{
[ImportMany]
public IEnumerable<IRule> Rules { get; set; }
public void Run()
{
// ...
// Initialise MEF
// ...
//
// Do I need to manually order Rules here?
//
foreach (IRule rule in Rules)
{
// Must execute in a specific order
rule.Execute();
}
}
}