Advertisement
Guest User

MEF DirectoryCatalog reads the same dll many times

a guest
Oct 9th, 2013
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. RegistrationBuilder regisBuilder = new RegistrationBuilder();
  2. regisBuilder.ForTypesDerivedFrom(typeof(IDCPlugin)).Export<IDCPlugin>();
  3.  
  4. var catalog = new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory+@"\Parts", regisBuilder);
  5. var agcatalogue = new AggregateCatalog(catalog);
  6. var container = new CompositionContainer(agcatalogue, CompositionOptions.DisableSilentRejection);
  7. container.ComposeParts();
  8.  
  9. var v = container.GetExportedValues<IDCPlugin>();
  10. foreach (var typeInstance in v)
  11. {
  12.     Console.WriteLine(typeInstance.Identifier+":"+typeInstance.Description);
  13. }
  14.  
  15. // At this point I have one class imported more times* even if I copy different assemblies into the directory (same interface).
  16. // *more times = number of assemblies there are in the directory.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement