views:

122

answers:

3

Hi

quick question for my MVP implementation:

currently I have the code below, in which both the presenter and view are resolved via the container.
Then the presenter calls View.Init to pass himself to the view.

I was wondering however if there is a way to let the container fix my circular reference (view -> presenter, presenter -> view).

class Presenter : IPresenter {
   private View _view; 

   public Presenter(IView view, ...){
    _view = view;
    _view.Init(this)
   }
}

class View : IView {
 private IPresenter _presenter;
 public void Init(IPresenter presenter){
  _presenter = presenter;
 }
}

Kind regards

Frederik

A: 

As long as you put both Presenter and View inside the same csproject, there shouldn't be any circular reference

Ngu Soon Hui
it's about runtime dependencies references, not about code references.
Mauricio Scheffer
A: 

This might help:

Mauricio Scheffer
Hithe first link looks like an answer, but the problem is that I really don't want to use events for view -> presenter communication.In the end I should be able to use the container in one go, however seeing as the lifecycle for the presenter and view are transient.. it creates two presenters (one requested, one for the view)..
Frederik
A: 

You may want to take a look at this StackOverflow answer.

Mark Seemann