ImportConstructor allows you to annotate a constructor in such a way that the Composer will call it when it creates an object of that class.
Lets see the code how it works :
public class ExportContainer
{
[ImportingConstructor]
public ExportContainer([Import(AllowDefault=true)]Action specialDelegate)
{
this.MyActionDelegate = specialDelegate;
}
public string ExportName { get; set; }
[Export]
[ExportMetadata("Name", "Plugin from Plugin1")]
public string GetName()
{
this.ExportName = "Plugin from Plugin1";
if (this.MyActionDelegate != null)
this.MyActionDelegate(this.ExportName);
Read more: Daily .Net Tips
QR: