Hi i have this class to instantiate DAL classes:
public class Factory
{
public static T GetInstance<T>() where T : new()
{
return new T();
}
}
I want to make my application capable of using multiple databases. I was planning on setting the database in my web.config and then pass in that setting possibly to the factory class where it will return the correct DAL class. I think my methodology is ok im just a bit stuck on how to implement it whilst keeping it generic.
Maybe something like this:
public class Factory
{
private static readonly string dbType = ConfigurationSettings.Appsettings["SqlServer"];
public static T GetInstance<T>() where T : new()
{
switch(dbType)
{
case "SqlServer":
return new T(); //Not sure what to put here.
break;
case: "MySql":
return new T();
break;
default: "No datasource";
}
}
}
If anyone could help or point me in the right direction that would be great.
Thanks in advance.