Guest User

Untitled

a guest
Dec 11th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.Composition;
  4. using System.ComponentModel.Composition.Hosting;
  5. using System.ComponentModel.Composition.Primitives;
  6. using SharedContracts;
  7.  
  8. namespace MefSimpleDemo
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. try
  15. {
  16. // Production code would usually load the directory from config
  17. var catalog = new DirectoryCatalog(@"..\..\..\Plugins");
  18. var container = new CompositionContainer(catalog);
  19. var pluginRepository = new PluginRepository()
  20. {
  21. CalculationServices = container.GetExportedValues<ICalculationService>()
  22. };
  23.  
  24. foreach (var calculationService in pluginRepository.CalculationServices)
  25. {
  26. const int number1 = 10;
  27. const int number2 = 20;
  28. int result = calculationService.Calculate(number1, number2);
  29.  
  30. string output = string.Format("calculationService.Calculate({0},{1}) = {2}", number1, number2, result);
  31.  
  32. Console.WriteLine(output);
  33. }
  34. }
  35. catch (Exception e)
  36. {
  37. Console.WriteLine(e.Message);
  38. }
  39. finally
  40. {
  41. Console.WriteLine("Press [ENTER] to exit the application");
  42. Console.ReadLine();
  43. }
  44. }
  45. }
  46. }
Add Comment
Please, Sign In to add comment