我试图找出MEF的构造函数注入属性.我不知道如何告诉它加载构造函数的参数.
这是我正在尝试加载的属性
[ImportMany(typeof(BUsers))]
public IEnumerable<BUsers> LoadBUsers { get; set; }
Run Code Online (Sandbox Code Playgroud)
这是我用来导入程序集的代码.
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);
}
Run Code Online (Sandbox Code Playgroud)
这是我正在尝试加载的类
[Serializable]
[Export(typeof(BUsers))]
public class EditProfile : BUsers
{
[ImportingConstructor]
public EditProfile(string Method, string Version)
{
Version = "2";
Action = "Edit";
TypeName = "EditProfile";
}
Run Code Online (Sandbox Code Playgroud) 我正在研究MEF,但我无法解决问题.
我有一个名为MainMEF的主应用程序,以及一个名为SimpleModule的简单模块.这个包含一个动态加载的UserControl.
当MainMEF启动时,我可以向模块传递对MainMEF中包含的主应用程序的引用.
我怎么能解决这个问题?