Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Composition;
  4. using System.Composition.Hosting;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9.  
  10. namespace ConsoleApplication1
  11. {
  12. class Program
  13. {
  14. [Export]
  15. public sealed class A
  16. {
  17. [Import]
  18. public B B { get; set; }
  19.  
  20. [OnImportsSatisfied]
  21. public void OnImportsSatisfied()
  22. {
  23. Console.WriteLine("From A");
  24. }
  25. }
  26.  
  27. [Export]
  28. public sealed class B
  29. {
  30. [Import]
  31. public C C { get; set; }
  32.  
  33. [OnImportsSatisfied]
  34. public void OnImportsSatisfied()
  35. {
  36. Console.WriteLine("From B");
  37. }
  38. }
  39.  
  40. [Export]
  41. public sealed class C
  42. {
  43. [OnImportsSatisfied]
  44. public void OnImportsSatisfied()
  45. {
  46. Console.WriteLine("From C");
  47. }
  48. }
  49.  
  50. static void Main(string[] args)
  51. {
  52. using(var container = new ContainerConfiguration().WithAssembly(Assembly.GetAssembly(typeof(A))).CreateContainer())
  53. {
  54. container.GetExport<A>();
  55. }
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement