【发布时间】:2016-03-16 19:44:53
【问题描述】:
我有一个 Windows 窗体应用程序,其中包含 1 个解决方案中的 3 个项目。
Hall.Client
Hall.Admin
Hall.Processor
Hall.Client 和Hall.Admin 需要Hall.Processor 作为参考。 Hall.Processor 由于循环依赖,无法同时添加对 Hall.Client 和 Hall.Admin 的引用。
我只需要在Hall.Processor中获取每个调用者类的实例@
在Hall.Client 我有一个类叫做 Canopy
public class Canopy : System.Windows.Form
{
public void SetProcessName(string name)
{
this.txtProcessName.Text = name;
}
}
在Hall.Admin我有一个叫Roof的类
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");
}
}
我需要建议如何解决我的问题。有没有与我的问题相关的设计模式?
【问题讨论】:
标签: c# class design-patterns .net-assembly circular-dependency