2012-12-12 39 views
1

我正在使用MEF。我的应用程序是开放式的,但我仍然希望将它从扩展它的人中隐藏起来。导入一个类而不导出它

例如BaseAssembly有

public class ListContainer 
{ 
    [ImportMany(typeof(IBase))] 
    public List<IBase> MyObjects { get; set; } 

    public void AssembleDriverComponents() 
    { 
     .... Some code to create catalogue.. 
     //Crete the composition container 
      var container = new CompositionContainer(aggregateCatalog); 

      // Composable parts are created here i.e. the Import and Export components assembles here 
      container.ComposeParts(this); 
    } 
} 

其他组件将指基座组件。

ReferenceAssembly将有

[Export(typeof(IBase))] 
public class MyDerived 
{ 
    public MyDerived() 
    { } 
} 

我想避免这种属性,它是在引用的程序集派生类。

可能吗?

回答

2

我认为你要找的是InheritedExport属性。你可以在你的IBase界面上使用它,它会自动导出任何执行IBase的类。

[InheritedExport(typeof(IBase))] 
public interface IBase 
{ 
    // ... 
} 

public class MyDerived : IBase 
{ 
    // This class will be exported automatically, as if it had 
    // [Export(typeof(IBase))] in its attributes. 
} 

您可以阅读更多关于继承导出here

+0

是的..我认为它应该适合我。 –