I'm not finding any guidance on how to implement MEF's RegistrationBuilder (Convention model) in Prism - can you provide an example of a best pattern and practice for this?
Below, in my POC, I implement what little documentation I can find on the convention model topic to successfully execute imported commands but only if I manually satisfy imports.
Below, in my POC, I implement what little documentation I can find on the convention model topic to successfully execute imported commands but only if I manually satisfy imports.
[ImportMany]
public IEnumerable<ICommand> Commands { get; set; }
protected override void ConfigureAggregateCatalog()
{
base.ConfigureAggregateCatalog();
// Add this class
AggregateCatalog
.Catalogs
.Add(new AssemblyCatalog(typeof(QuickStartBootstrapper).Assembly));
// Add the AddIns folder
var catalog = new DirectoryCatalog("AddIns");
AggregateCatalog.Catalogs.Add(catalog);
// Export all ICommand values and import them into the Commands property
var conventions = new RegistrationBuilder();
conventions.ForTypesDerivedFrom<ICommand>().Export<ICommand>();
conventions.ForType<QuickStartBootstrapper>()
.ImportProperty<ICommand>(p => p.Commands);
var thisAssemblyCatalog = new
AssemblyCatalog(typeof (CallbackLogger).Assembly, conventions);
this.AggregateCatalog.Catalogs.Add(thisAssemblyCatalog);
using (var service = thisAssemblyCatalog.CreateCompositionService())
{
service.SatisfyImportsOnce(this, conventions);
foreach (var command in Commands)
{
if (command.CanExecute(moduleManager))
command.Execute(Logger);
}
}
}