In my program I am using the following statements in program.cs
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var init = new Initializer();
var container = new CompositionContainer(new DirectoryCatalog(Environment.CurrentDirectory));
container.ComposeExportedValue(string.Empty);
container.SatisfyImportsOnce(init);
if (init.PreleminaryCheck())
{
Form1 frm = new Form1();
container.SatisfyImportsOnce(frm);
Application.Run(frm);
}
I am exporting class like below
[Export(typeof(DatabaseMaster))]
public class DBManager : DatabaseMaster
[ImportingConstructor]
public DBManager(string filepath = "")
{
DbPath = filepath;
}
The problem is i am only getting the variable initialized in the Initializer class, In the form class the instance of DBManager is always null. I tried calling SatisfyImportOnce on Form1 variable but no luck.
我通过将成员函数调用从构造函数移到form load方法来解决了这个问题,
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.