This is a very good need that asks for loosely coupled business and data layer. You can very well make use of Dependency Injection here. This should make it clear:
public class PresentationLayer
{
private void ClickDataAccessSelectionButton(object sender, EventArgs e)
{
Entity entity = new Entity();
BusinessLayer businessLayer = new BusinessLayer();
businessLayer.Provider = "user selection here";
businessLayer.UpdateData(entity);
}
}
public class BusinessLayer
{
private string _provider;
public string Provider
{
get
{
return _provider;
}
set
{
_provider = value;
SetProvider();
}
}
public DataAccess DataAccessLayer { get; set; }
private void SetProvider()
{
if (_provider == "SQL")
{
DataAccessLayer.Command = new SqlCommand();
DataAccessLayer.Connection = new SqlConnection();
}
else
{
}
}
public void UpdateData(Entity yourBusinessObject)
{
DataAccessLayer.Update(yourBusinessObject);
}
}
public class DataAccess
{
public IDbConnection Connection
{
get;
set;
}
public IDbCommand Command
{
get;
set;
}
public void Update(Entity yourBusinessObject) { }
}
Consider the code above. Here, the data access layer can adapt to any provider who implements IDbConnection, IDbCommand etc interfaces. When the user selects the provider on the screen, then the specific provider will be assigned to the data access layer.
You can make use of Unity application block too for this. This should help you get things configurable through the configuration files. You can do this on your own too.
Hope this helps. :)