I have the following items in my solution:
public interface IHandle<TEvent>
{
void Handle(TEvent event);
}
public interface IPresenter<TView>
{
}
public abstract class Presenter<TView> : IPresenter<TView>
{
protected view;
public TView View
{
set { view = value;}
}
// snip...
}
public interface IMyPresenter : IPresenter<IChangeRequestReviewManagementView>
{
// snip...
}
public class MyPresenter : Presenter<MyView>, IMyPresenter, IHandle<CustomEvent>
{
// snip...
}
And have the following registration for Windsor to register the presenters:
container.Register(AllTypes.Of(typeof(IPresenter<>))
.FromAssemblyNamed("Project.Presentation")
.WithService.Select((type, baseType) => new Type[] {GetInterfaceFromConvention(type)})
.Configure(config => config.LifeStyle.PerWebRequest));
private static Type GetInterfaceFromConvention(Type type)
{
return (from found in type.GetInterfaces()
where found.Name.Equals("I" + type.Name)
select found).FirstOrDefault();
}
This works perfectly and I can resolve the presenters in my pages using:
public IMyPresenter Presenter
{
set
{
presenter = value;
}
}
Using this http://code.google.com/p/sneal/wiki/AspNetWindsorModule, the problem comes when I try to wire in the support for handling events supplied via a separate EventAggregator which calls implementers of IHandle<>. I added this registration:
container.Register(AllTypes.Of(typeof(IHandle<>))
.FromAssemblyNamed("Project.Presentation")
.BasedOn(typeof(IHandle<>))
.WithService.Base());
As this works for other areas that implement IHandle<> but after adding this the container cannot no longer resolve IMyPresenter to MyPresenter, so I must be missing something?!