I am using MVP pattern to develop a Windows Form using c#.
I have a presenter MainPresenter
which has reference of InfoPresenter
so MainPresenter
can access InfoPresenter
's methods.
Now I want to access MainPresenter
's methods in InfoPresenter
. If I give reference of MainPresenter
into InfoPresenter
the application will break with following error.
System.StackOverflowException: 'Exception of type 'System.StackOverflowException' was thrown.'
Following is the code that is breaking:
MainPresenter
class MainPresenter : IMainPresenter
{
private IInfoPresenter _infoPresenter;
public MainPresenter(IInfoPresenter infoPresenter)
{
_infoPresenter = infoPresenter;
}
}
InfoPresenter
class InfoPresenter : IInfoPresenter
{
private IMainPresenter _mainPresenter;
public InfoPresenter(IMainPresenter mainPresenter)
{
_mainPresenter = mainPresenter;
}
}
If I remove the reference of MainPresenter
from second class (InfoPresenter
) it will work fine, but then I want to access some of its (MainPresenter
) method into InfoPresenter
and vice versa.