Dynamic linking

  • Thread starter Thread starter Jon Harrop
  • Start date Start date
J

Jon Harrop

I am writing a library (a DLL) and would like it to load the DLLs that it
depends upon only as they are needed. For example, I would like to give the
user a choice between MDX, WPF and XNA without having to load all three.

How can this be achieved?
 
I am writing a library (a DLL) and would like it to load the DLLs that it
depends upon only as they are needed.

..NET does lazy loading of assemblies automatically... so just don't
call any methods that would use things you don't want! Note that JUT
on a method involving a new dll will cause that dll to load.
Alternatively (and perhaps better) look into using an interface/
provider approach so that your main system only knows about IFoo, and
have concrete (WPF, MDX, etc) IFoo providers that are provided
(dependency inversion) at runtime.

Marc
 
Marc said:
.NET does lazy loading of assemblies automatically... so just don't
call any methods that would use things you don't want! Note that JUT
on a method involving a new dll will cause that dll to load.
Alternatively (and perhaps better) look into using an interface/
provider approach so that your main system only knows about IFoo, and
have concrete (WPF, MDX, etc) IFoo providers that are provided
(dependency inversion) at runtime.

Then how do I politely handle the eventuality that the user does not have
the required DLL installed?
 
Tricky, and it varies from case to case. Using a plugin (dependency
inversion) approach is probably the easiest, as you have more control;
If you scatter your "real" code with MDX/WPF etc types, the raw JIT
failure will blow up in a messy way. You might be able to get away
with just exception handling if you use an interface wrapper (without
worrying about plugins) - I use this approach to load whichever GIS
[mapping/routing/etc] system the user has installed - of course, I
already neede the interface approach as each has very different raw
APIs. I just have a few methods which (in turn) attempt to initialise
and return the wrapper objects (the concrete classes that negotiates
between IFoo and the various APIs); those that return successfully I
can use - those that throw I can't.

Marc
 

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

Back
Top