I'm working on a simple, internal ASP.NET app for a small company. I've designed the data access layer so it's database-agnostic.
I have the following:
- IDataHelper - An interface requiring methods such as FillDataTable(), ExecuteNonQuery(), etc.
- MySqlHelper - Implements IDataHelper for MySQL, the only database I support so far.
- Static data access classes - Encapsulate data access methods for different parts of the app. They call methods on an IDataHelper to execute queries.
And finally, I have a static class that creates an IDataHelper for the data access classes to call. In the future it will create the appropriate helper based on the database specified in the config file. For now it's just hard-coded to create a MySqlHelper:
public static class DataHelperContainer
{
private static IDataHelper dataHelper;
public static IDataHelper DataHelper
{
get { return dataHelper; }
}
static DataHelperContainer()
{
string connectionString = ConfigurationManager
.ConnectionStrings["myapp"].ConnectionString;
// Support for other databases will be added later.
dataHelper = new MySqlHelper(connectionString);
}
}
My questions are:
- What should I name this? "DataHelperContainer" doesn't seem right, since that implies some kind of list.
- Is this a good or bad design? If it's bad, what are its faults?
- Is this similar to any known design pattern? Can it be refactored to conform to one? It seems remotely like a factory, but I'm not sure.
Sorry about the long post and multiple questions. :)
Thanks!