我有一個Windows窗體應用程序包含3個項目中的1個解決方案。來自調用者類的調用方法,避免循環依賴
Hall.Client
< - 的Winforms
Hall.Admin
< - 的Winforms
Hall.Processor
< - 類庫
Hall.Client
和Hall.Admin
需要Hall.Processor
作爲參考。由於循環依賴性,Hall.Processor
無法添加對Hall.Client
和Hall.Admin
的引用。 所有我需要的是讓每個呼叫者類的實例在Hall.Processor
在Hall.Client
我有一個叫天幕
public class Canopy : System.Windows.Form
{
public void SetProcessName(string name)
{
this.txtProcessName.Text = name;
}
}
類Hall.Admin
我有一個名爲屋頂
public class Roof : System.Windows.Form
{
public void SetProcessName(string name)
{
this.txtProcessName.Text = name;
}
}
我有課Builder類中的Hall.Processor
中的方法
public class Builder
{
Form form;
public Builder(Form form)
{
//Here the main problem.
//if the caller class is Hall.Admin.Roof then this.form should be Hall.Admin.Roof
//if the caller class is Hall.Client.Canopy then this.form should be Hall.Client.Canopy
}
public void SetProcessName()
{
//How to call method in caller class directly from this class
//if(Admin.Roof) then form.SetProcessName("something about admin");
//if(Client.Canopy) then form.SetProcessName("something about client");
}
}
我需要建議如何解決我的問題。有沒有與我的問題有關的設計模式?
我仍然困惑你的解釋。網絡上有很多例子,它們都不符合我的需求。 – derodevil
@dededevil,什麼是完全混淆?你是否熟悉[C#中的接口](http://stackoverflow.com/a/22549046/1768303)? – Noseratio
是的,我。我在想的是工廠模式,而不是DI。這就是我很困惑。 – derodevil