castle IOC - resolving circular references
Asked Answered
P

2

3

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

Pseudo answered 23/11, 2009 at 13:27 Comment(1)
What exactly do you mean by "fix my circular reference." In other words what would you expect the fix to be; which one would lose the reference to the other?Hemmer
H
0

You could use a property setter instead of passing the reference into the constructor.

Hebrew answered 25/12, 2010 at 11:15 Comment(0)
I
-1

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

Inerasable answered 23/11, 2009 at 13:43 Comment(1)
it's about runtime dependencies references, not about code references.Heterodyne

© 2022 - 2024 — McMap. All rights reserved.