I am trying to get the Exported Properties in my defined classes, but I think something is missing that I don't know of. Here is my Handler class:
public class Handler
{
public string Message { get; private set; }
public void Create(string msg)
{
Message = msg;
}
}
My HandlerUser class is:
public class HandlerUser
{
[Export(typeof(Handler))]
public Handler MyHandler { get; set; }
public string Name { get; set; }
public HandlerUser() { MyHandler = new Handler(); }
}
And in my program.cs I have:
var catalogs = new AggregateCatalog();
var catalog = new ApplicationCatalog();
catalogs.Catalogs.Add(catalog);
CompositionContainer pluginsCompositionContainer = new CompositionContainer(catalogs);
HandlerUser u1 = new HandlerUser();
u1.MyHandler.Create("U1");
HandlerUser u2 = new HandlerUser();
u2.MyHandler.Create("U2");
var exports = pluginsCompositionContainer.GetExports<Handler>();
Console.Write(exports.Count());
I expect to see 2 exports, and They should have "U1","U2" as their message, But I only see one, and the message is null. I can't figure out what's missing, I simple want to have an export of Every Handler
made in code, and just be able to do some logic. Any help would be great.