views:

182

answers:

2

I have the following class:

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;
 }
}

and this is the Presenter code:

public class Presenter<T> where T : IView
{
 public T View { get; private set; }

 public Presenter(T view)
 {
  this.View = view;
 }
}

I'd like to pass the current instance of ViewPage to TPresenter via Windsor instead of having it instantiate a new object. Is this possible?

+1  A: 

Check this blog. The author explains the solution for your exact problem.

Lamar
The URL didn't exactly discuss what I wanted, but he was doing what I wanted. Thanks!For anyone who is wondering.. You use the Resolve method on the container.
sontek
A: 

sorry to bump this but i have the same question and the check this blog link doesn't work any more. an the short description dident realy help me out. a little more info would help allot.

i would like to use my logedin user as a container dependency.

LordSauron
You can use either DynamicParameters http://kozmic.pl/archive/2009/12/10/castle-windsor-new-feature-ndash-dynamic-parameters-from-registration-site.aspx or TypedFactory http://kozmic.pl/archive/2009/12/24/castle-typed-factory-facility-reborn.aspx whichever works better for you
Krzysztof Koźmic