0

Until now by Business Layer was instantiating one instance of my needed DAL objects:

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

A new set of front end applications need to access data on 4 different servers (SAME Data Access Layer implementation with 4 different connectionstrings).

One way is to let Ui instantiate 4 BarcodeBLL objects and do the job which i dont want in any case , because i would transfer business logic to UI.

So i have to find a proper way of instantiating from 1 to 4 DAL instances according to the UI application.

One thought is to pass a List<ERPConfig> and/or a List<BarcodeDALConfig> and let somewhow the contructor (???) decide what to do..

I started doing it like 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));
        }
    }
}

This is what i am looking for..

Additional Info for clarity:

My goal as i see it now is for ONE method in BLL to be able to get from 1 to 4 DAL objects and execute methods in each of them.

Possible scenarions:

UI asks from BLL method GetItemList data from 2 countries.

Bll must unserstand somehow to create 2 DAL objects withg the correct connectionstring and do its job.

So i am consolidating operations for all my servers in the BLL and letting DAL to be alone.

e4rthdog
  • 5,103
  • 4
  • 40
  • 89
  • Are we talking about 4 (different) data classes? Or 1 class, re-used for times with different connection strings? – Louis van Tonder Aug 07 '14 at 09:18
  • What i think its best (and fast for me now) is to keep the DAL as it is and make BLL create up to 4 of DAL classes....Servers are AS400 using dapper with oledbconnection – e4rthdog Aug 07 '14 at 09:20

2 Answers2

0
  1. Create an Enum, and modify your constructor to take a variable of the Enum?
  2. Catch the incoming enum in init, and set a private property/variable.
  3. Then inside your class, access the correct DAL based on the current selected enum.

from Business Layer

Dim d as new DAL(option1)

or

Dim d as new DAL(option2)
Louis van Tonder
  • 3,664
  • 3
  • 31
  • 62
  • Maybe i dont get it, but how this is gonna serve the need for ONE method execution from BLL to execute up to 4 methods in DAL? – e4rthdog Aug 07 '14 at 09:06
  • I see, but i want from 1 to 4 DAL instances nad this by dynamic because maybe one UI will ask for data from 2 servers, naother from 1 another from all 4... – e4rthdog Aug 07 '14 at 09:09
  • It can't automagically know what to do? The UI needs to ask for what it wants? Do you mean that you need to be able to specify an (n) amount of sources? Or will it be fixed... (a,b) or (a) or (b,d) ? Or will it in future handle any combination not know to you now? If so, you will have to use a list/array as you suggested... – Louis van Tonder Aug 07 '14 at 09:12
  • I am updating the additional info for clarity form your questions. – e4rthdog Aug 07 '14 at 09:15
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.

e4rthdog
  • 5,103
  • 4
  • 40
  • 89