Guest User

Untitled

a guest
Oct 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. var c = new WindsorContainer();
  2. var collectionResolver = new CollectionResolver(c.Kernel);
  3. c.Kernel.Resolver.AddSubResolver(collectionResolver);
  4. c.Register(Component
  5. .For(typeof(IOpenGeneric<>))
  6. .ImplementedBy(typeof(OpenGenericImpl<>))
  7. .LifestyleTransient()
  8. );
  9. c.Register(Component
  10. .For<MyProfile>()
  11. .LifestyleTransient()
  12. );
  13. c.Register(Component
  14. .For<MyClass>()
  15. .LifestyleTransient()
  16. );
  17. c.Register(Component
  18. .For<MyOtherClass>()
  19. .LifestyleTransient()
  20. );
  21.  
  22. class MyOtherClass
  23. {
  24. private readonly MyClass _cls;
  25.  
  26. public MyOtherClass(MyClass cls)
  27. {
  28. _cls = cls;
  29. }
  30. }
  31.  
  32. class MyClass
  33. {
  34. private readonly IOpenGeneric<MyProfile> _s;
  35.  
  36. public MyClass(IOpenGeneric<MyProfile> s)
  37. {
  38. _s = s;
  39. }
  40. }
  41.  
  42. class Profile
  43. {
  44. }
  45.  
  46. class MyProfile : Profile
  47. {
  48. }
  49.  
  50. interface IOpenGeneric<out T>
  51. where T : Profile
  52. {
  53. }
  54.  
  55. class OpenGenericImpl<T> : IOpenGeneric<T>
  56. where T : Profile
  57. {
  58. private readonly T _t;
  59.  
  60. public OpenGenericImpl(T t)
  61. {
  62. _t = t;
  63. }
  64. }
Add Comment
Please, Sign In to add comment