0

到目前为止,业务层正在实例化我需要的 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。

所以我必须找到一种根据 UI 应用程序实例化 1 到 4 个 DAL 实例的正确方法。

一个想法是传递 aList<ERPConfig>和/或 aList<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 对象并在每个对象中执行方法。

可能的场景:

UI 询问来自 2 个国家的 BLL 方法 GetItemList 数据。

Bll 必须以某种方式使用正确的连接字符串创建 2 个 DAL 对象并完成其工作。

因此,我正在整合 BLL 中所有服务器的操作,并让 DAL 独处。

4

2 回答 2

0

The solution i followed is this:

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));
        }
    }
}

So the BLL layer will accept a dictionary of variable number of entries.

UI Application will be responsible to sent the dictionary so it is its own decision of how many DALs will be instantiated.

Moreover, BLL methods will be responsible to check for the existence of dictionary entries and act accordingly.

于 2014-08-08T11:39:27.303 回答
0
  1. 创建一个Enum,并修改您的构造函数以获取Enum?
  2. 在 init 中捕获传入的枚举,并设置一个私有属性/变量。
  3. 然后在您的班级内,根据当前选择的enum.

从业务层

Dim d as new DAL(option1)

或者

Dim d as new DAL(option2)
于 2014-08-07T08:55:06.057 回答