我有以下课程:
public class ViewPage<TView,TPresenter> : Page
where TView : IView
where TPresenter : Presenter<TView>
{
public ViewPage()
{
if (!(this is TView))
throw new Exception(String.Format("The view must be of type {0}", typeof(TView)));
IWindsorContainer container = new WindsorContainer();
container.AddComponent("view", typeof(IView), typeof(TView));
container.AddComponent("presenter", typeof(Presenter<TView>), typeof(TPresenter));
TPresenter presenter = container[typeof(TPresenter)] as TPresenter;
}
}
这是Presenter代码:
public class Presenter<T> where T : IView
{
public T View { get; private set; }
public Presenter(T view)
{
this.View = view;
}
}
我想通过Windsor将当前的ViewPage实例传递给TPresenter,而不是让它实例化一个新对象。这可能吗?