我想弄清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