私はオープンエンドのアプリケーションを開発しており、MEFは初めてです。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);
}
}
[InheritedExport(typeof(IBase))]
public abstract class Base : IBase
{
private IInfoBase infoBase;
//This is something which I want to do. If I have a derived class from Base.
Then It does not need to use ImportingConstructor.
[ImportingConstructor()]
public Base(InfoBase nfoBase)
{
this.infoBase = infoBase;
}
}
[InheritedExport(typeof(IInfoBase))]
public interface IInfoBase
{
string Category { get; set; }
}
public class InfoBase : IInfoBase
{
public string Category
{
get;
set;
}
}
他のアセンブリは、ベースアセンブリを指します。
ReferenceAssemblyには
public class Derived : Base
{
public Derived(BaseInfo info)
: base(info)
{
info.Category = "CategoryA";
}
}
この場合、MEFは派生オブジェクトのオブジェクトを作成していません。
要約すると、ImportingConstructor用のExplicitExportのようなものも必要です。