If you have the same interface, then you've done most of the work.
Go to:
12/1/2005
Understanding the Simple Factory Pattern
http://sholliday.spaces.live.com/blog/
I would use "reflection", or the "key" method. And create a Factory class.
( A factory class is a class that creates other classes)
You could have the key value in your config file.
Then you'd need a factory
public class TalkToDatabaseFactory
{
public static IMyDatabaseAccessInterface GetMyDatabaseAccessInterface ()
{
string key = "Access"; // read this from web.config file
switch (key.ToUpper())
{
case "ACCESS":
return new MyDatabaseAccess();
case "SQLSERVER":
return new SqlServerMyDatabaseAccess();
default:
throw new ArgumentException("The AnimalFactory was given a Bad Key");
}
}
}
<je**@derouse.comwrote in message
news:11**********************@79g2000cws.googlegro ups.com...
I have an application that can either connect to an access database or
a SQL Server database. I have 2 assemblies both implement the same
interface (IMyDatabaseAccessInterface for describing the data access
methods for the application.
One assembly is specific to use the Access database using the OLEDB
provider, the other is specific to SQL Server using the SQLServer
provider. I want to be able to use the SQL server provider for the SQL
server assembly.
My original thought was to have 2 compiled versions of the app, one for
Access and one for SQL Server. I believe there is a better way to do
this using the app.config file but am not sure exactly how to go about
it.
Any thoughts?
Thanks in advance
Jeff D.