Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var c = new WindsorContainer();
- var collectionResolver = new CollectionResolver(c.Kernel);
- c.Kernel.Resolver.AddSubResolver(collectionResolver);
- c.Register(Component
- .For(typeof(IOpenGeneric<>))
- .ImplementedBy(typeof(OpenGenericImpl<>))
- .LifestyleTransient()
- );
- c.Register(Component
- .For<MyProfile>()
- .LifestyleTransient()
- );
- c.Register(Component
- .For<MyClass>()
- .LifestyleTransient()
- );
- c.Register(Component
- .For<MyOtherClass>()
- .LifestyleTransient()
- );
- class MyOtherClass
- {
- private readonly MyClass _cls;
- public MyOtherClass(MyClass cls)
- {
- _cls = cls;
- }
- }
- class MyClass
- {
- private readonly IOpenGeneric<MyProfile> _s;
- public MyClass(IOpenGeneric<MyProfile> s)
- {
- _s = s;
- }
- }
- class Profile
- {
- }
- class MyProfile : Profile
- {
- }
- interface IOpenGeneric<out T>
- where T : Profile
- {
- }
- class OpenGenericImpl<T> : IOpenGeneric<T>
- where T : Profile
- {
- private readonly T _t;
- public OpenGenericImpl(T t)
- {
- _t = t;
- }
- }
Add Comment
Please, Sign In to add comment