How do you implement selectable alternative DLLs?

B

Byron

I've got a need to allow my application to use a differrent version of a data
access DLL based on a user's selection, or automatically discovered
difference. In particular, I have an application that I want the user to be
able to select the type of data source (Oraqcle, MSSQL, XML, Web Service,
etc) and the application will use the applicable DLL from among the multiple
DLLs provided with minimal coding.

Ideally, I would have a DLL for each of the data sources supported and would
just select one at startup and the code would remain the same for all calls
regardless of the source.

It's currently a 3-tier (GUI, business, data access) application supporting
only Oracle, but I need to support MSSQL, including Compact, as well as XML
files, and Web Services.

Each deployed location would use the data source type of their choice.

So, load the data access DLL at startup, and call it from the business layer
the same, regardless of its type, including static methods.

switch(database_type)
{
case MSSQL:
da = MSSQL.DLL
break;

case Oracle:
da = Oracle.DLL;
break;
}

da.Insert(Person);
da.Save(Person);

Thanks in advance for any suggestions.
 
J

Jani Järvinen [MVP]

Hello Byron,
I've got a need to allow my application to use a differrent version of a
data
access DLL based on a user's selection, or automatically discovered
difference.

To me it sounds you could take two routes: either you add all the different
DLLs as references to your project at development time, or create a fully
dynamic loading method to support DLLs that were not available at
development time.

As for the former, basic references to the DLLs would be enough. Then, based
on the user selection, you would instantiate the correct class. Remember,
that you would need to come up with an interface that all your data access
layer components would support, and then implement this interface in your
Oracle, SQL Server, etc. classes.

For the second option, you could dynamically load the given assembly,
construct a type instance from that DLL, and then proceed from there. Again,
a common interface would make things much easier. Start looking at the
Assembly class System.Reflection namespace and its Load method.

For examples, see here:

http://social.msdn.microsoft.com/Fo.../thread/20038c77-714a-461c-a75a-6c0570cdf8d1/

http://www.c-sharpcorner.com/upload...od10132008214835pm/dynamicassemblymethod.aspx

Hope this helps.

--
Regards,

Jani Järvinen
C# MVP
Vantaa, Finland
E-mail: (e-mail address removed)
Business: http://www.nimacon.net/
Personal: http://www.saunalahti.fi/janij/
 
J

John Vottero

Byron said:
I've got a need to allow my application to use a differrent version of a
data
access DLL based on a user's selection, or automatically discovered
difference. In particular, I have an application that I want the user to
be
able to select the type of data source (Oraqcle, MSSQL, XML, Web Service,
etc) and the application will use the applicable DLL from among the
multiple
DLLs provided with minimal coding.

Take a look at the Managed Extensibility Framework (MEF). It's available
now from Codeplex and will be part of V4.0 of the .NET Framework.

http://mef.codeplex.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top