我想弄清MEF的構造函數注入屬性。我不知道如何告訴它加載構造函數的參數。MEF構造函數注入
這是我試圖加載
[ImportMany(typeof(BUsers))]
public IEnumerable<BUsers> LoadBUsers { get; set; }
這裏是我使用導入組件代碼中的財產。
try
{
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly()));
catalog.Catalogs.Add(new DirectoryCatalog("DI"));
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
這裏是我想要當您使用ImportingConstructor屬性,參數來構造成爲進口加載
[Serializable]
[Export(typeof(BUsers))]
public class EditProfile : BUsers
{
[ImportingConstructor]
public EditProfile(string Method, string Version)
{
Version = "2";
Action = "Edit";
TypeName = "EditProfile";
}
我剛剛在CodePlex上下載了一個新的。 ComposeExportedValue()的方法不在CompositionContainer的類中。它在哪裏? – 2010-01-20 22:18:51
我想我找到了方法。它屬於AttributedModelServices類,其中方法被定義爲類CompositionContainer的擴展方法。 – 2010-01-20 22:32:20
@ David.Chu.ca是的,ComposeExportedValue是AttributedModelServices類的擴展方法。 – 2010-01-21 18:33:14