In order for this to work we would need to recursively check the type parameters. I dont think we do that currently, so the support is restricted to one level. In other words, ISomething<T> would work, whereas ISomething<SomethingElse<T>> would not.
On Wed, Jun 15, 2011 at 12:32 AM, PaulBowman <[email protected]> wrote: > Hi All. > > Can anybody explain why Windsor will not resolve the component. > > > using System; > using System.Collections.Generic; > using Castle.Windsor; > using Castle.MicroKernel.Registration; > namespace WindsorIOCProblem > { > class Program > { > static void Main(string[] args) > { > IWindsorContainer container = new WindsorContainer(); > > container.Register(Component.For<IEventHandler<SomethingCreatedEvent>>().ImplementedBy<CreateSomethingEventHandler>()); > > var publisher = new Publisher(container); > > // This works > var created = new SomethingCreatedEvent(); > publisher.Publish(created); > > // This does not. > var list = new List<IEvent>() { new > SomethingCreatedEvent() }; > foreach (var e in list) > publisher.Publish(e); > > } > } > > public interface IEvent { } > > public class SomethingCreatedEvent : IEvent { } > > public interface IEventHandler<T> where T : IEvent > { > void Handle(IEvent @event); > } > > public class CreateSomethingEventHandler : > IEventHandler<SomethingCreatedEvent> > { > void IEventHandler<SomethingCreatedEvent>.Handle(IEvent > @event) > { > Console.WriteLine(this.GetType().Name); > } > } > > public class Publisher > { > public Publisher(IWindsorContainer container) > { > _container = container; > } > > public void Publish<T>(T @event) where T : IEvent > { > var handler = _container.Resolve<IEventHandler<T>>(); > handler.Handle(@event); > } > > private IWindsorContainer _container; > } > } > > In the code example I give (which should run with a reference to > Windsor). > If I call Publisher.Publish with the explicit type Windsor can resolve > the component. However if I use the second method (which is what to > do). Windsor will not resolve the component and throws an exception > telling me it cannot find a service supporting IEvent. I can > understand why Windsor cannot find a service implementing IEvent. > My question is how can I Windsor to resolve correctly? > > Thanks > > Paul > > -- > You received this message because you are subscribed to the Google Groups > "Castle Project Users" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/castle-project-users?hl=en. > > -- Cheers, hammett http://hammett.castleproject.org/ -- You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.
