I have a MDI MyMDIWinForm that needs an instance of IGUIErrorHanlder for error handling, At the same time IGUIErrorHanlder depends on the MDI MyMDIWinForm for having a place from where to launch pop-ups and other stuff.
public class MyMDIWinForm
{
readonly IGUIErrorHanlder GUIErrorHandler;
public MyMDIWinForm(IGUIErrorHanlder guiErrorHandler)
{
GUIErrorHandler=guiErrorHandler;
}
public void DumbMethod()
{
try
{
//dumb code
}
catch(Exception e)
{
GUIErrorHandler.OnError(e.Message);
}
}
}
public FormGUIErrorHanlder:IGUIErrorHanlder
{
readonly Form Parent;
public FormGUIErrorHanlder(Form form)
{
//this form should be the MDI form
Parent=form;
}
public OnError(string message)
{
Parent.ShowDialog(new PopUpForm(message));
}
}
I want that MyMDIWinForm has a instance of FormGUIErrorHanlder and that FormGUIErrorHanlder has the same instance of MyMDIWinForm
How do I remove that circular dependency?
Many thanks
MyWinForm
inFormGUIErrorHanlder
. I just see it using some form that could be any form. If there is a circular dependency here it isn't a static one. Maybe pass it some other form? – candied_orange Jun 19 '18 at 6:13