到目前为止,业务层正在实例化我需要的DAL对象的一个实例:
public class BarcodeBLL : IBarcodeBLL
{
private BarcodeConfig _MyConfig;
private readonly IJDE8Dal _JDE8dal;
private readonly IBarcodeDal _barcodeDal;
public BarcodeBLL(BarcodeConfig MyConfig, ERPConfig erpConfig, BarcodeDALConfig barcodeDalConfig)
{
_MyConfig = MyConfig;
_JDE8dal = new JDE8Dal(erpConfig);
_barcodeDal = new BarcodeDAL(barcodeDalConfig);
}
...
...
}
一组新的前端应用程序需要访问4个不同服务器上的数据(使用4个不同的连接字符串实现相同的数据访问层)。
一种方法是让Ui实例化4个BarcodeBLL对象并完成在任何情况下都不想做的工作,因为这会将业务逻辑转移到Ui。
所以我必须找到一个适当的方法实例化从1到4个DAL实例根据UI应用程序。
一个想法是传递一个List<ERPConfig>
和/或List<BarcodeDALConfig>
,让构造器(???)决定做什么…
我开始这样做:
public partial class BusinessLayer
{
private readonly Dictionary<string,IJDE8Dal> _JDE8dals;
public BusinessLayer(Dictionary<string,JDEDalConfig> jdeConfigs)
{
foreach (var j in jdeConfigs)
{
_JDE8dals.Add(j.Key,new JDE8Dal(j.Value));
}
}
}
这就是我要找的…
附加信息清晰:
我现在看到的目标是BLL中的一个方法能够从1到4个DAL对象中获取并在每个对象中执行方法。
可能scenarions:
UI从BLL方法请求来自2个国家的GetItemList数据。
ll必须以某种方式理解创建两个具有正确连接字符串的DAL对象并完成其工作。
因此,我正在整合BLL中所有服务器的操作,并让DAL单独操作。
- 创建
Enum
,并修改构造函数以获取Enum
的变量 - 在init中捕获传入的enum,并设置一个私有属性/变量
- 然后在你的类中,基于当前选择的
enum
访问正确的DAL。
from Business Layer
Dim d as new DAL(option1)
或
Dim d as new DAL(option2)
我遵循的解决方案是:
public partial class BusinessLayer
{
private readonly Dictionary<string,IJDE8Dal> _JDE8dals;
public BusinessLayer(Dictionary<string,JDEDalConfig> jdeConfigs)
{
foreach (var j in jdeConfigs)
{
_JDE8dals.Add(j.Key,new JDE8Dal(j.Value));
}
}
}
因此,BLL层将接受包含可变数量条目的字典。
UI应用程序将负责发送字典,因此它自己决定将实例化多少DALs。
此外,BLL方法将负责检查字典条目的存在并采取相应的行动。