views:

42

answers:

1

Hi,

I'm in front of a classic circular dependencies problem but the solution I've found (create a third assembly) does not seem to be ok with my view-presenter pattern.

I need to reference my presenter in my view assembly I need to reference my interface(which are in the same assembly than the presenter) in my view assembly

ok so I reference my presenter / interface assembly in the view since they are all in the same place.

and now the problem comes : I need to reference my view in my presenter/interfaces assembly to be able to use one of my view type (non-system type, custom control) to define a property and accessors in my interface. I can't because of a circular dependency, and I think that even if I move my interface in a third assembly, I will always have a CD between this new assembly and the view (because my view needs my interface and my interface needs my view)

the goal is to set a property and accessors in my interface to be able to access to a control in my view from my presenter so I need a reference to use my control type in the interface.

It's not easy to be clear so feel free to ask me more,

Thanks a lot in advance to everybody.

Best regards.

+1  A: 

Interfaces should live on there own as a rule. When you need isolation of implementations (such as in the reference between views and presenters) you use an interface. So you should have a presenter interface and view interface, if it is necesarry for them both to know of eachother rather than just one knowing of the other.

Example:

Interface.dll:

public interface IMyView { string title; }
public interface IMyPresenter { string GetTitle(); }

View.dll:

public MyView : IMyView
{
    private IMyPresenter _myPresenter;
    public string Title { get { return _myPresenter.GetTitle(); } }
}

Presenter.dll:

public MyPresenter : IMyPresenter
{
    private IMyView _myView;

    public string GetTitle()
    {
        return ResourceManager["titleResource"];
    }
}

Though in my understanding of a model view presenter, doesn't the view just publicize everything the presenter needs, and the view doesn't know about the presenter, rather you hand the IView to the presenter and it binds itself to the view everywhere necesarry?

Jimmy Hoffa
thanks for the time you took for the reply, I'm gonna see that this weekend
benj007