MEF允许你通过使用<代码>ImportMany属性进口多个部件。 它如何确定收回相关出口的先后次序,并增加多少出口量。 例如,我如何进口不得不按特定顺序发射的多个《国际规则》? 我认为,唯一一种办法是在《规则》中以人工方式拥有传令财产:
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();
}
}
}