How do you implement selectable alternative DLLs?

  • Thread starter Thread starter Byron
  • Start date Start date
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.
 
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/
 
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/
 
Back
Top