Dynamically Loading DLL's

  • Thread starter Thread starter j0hnj0hn
  • Start date Start date
J

j0hnj0hn

I tried in the VB.NET group and didn't get much help, so I am coming to this
group in hopes of getting some help. I have a new program I am architecting
that will encompass the whole plant I am working at. This program will track
product through the manufacturing process allowing users to record
information as the product is created. The "core" of this program will all
contain the same functions, login, security, process deviation, etc. I would
like to launch this core program and have it look in a plugin folder for any
DLL's (user controls) and load them into the program for use. Each step in
our process is a cell that does a certain manufacturing process on a piece.
I would like to create a usercontrol/process for each cell, test it, qualify
it, then be able to put the DLL in the directory to be recognized and loaded
automatically. The cell DLL needs to contain its own processing requirement
such as forumlas, routing, etc and have its own display (in the form of a
user control). I have been looking around the net and have seen some
interesting options. I looked at System.Addin, but found it convoluted and
difficult. I and going down the road of creating the interfaces for the all
cells to use, but need some guideance on how to dynamically load these DLL's
into the framework. Anyone know of some code or articles that could help me
load usercontrols at startup?

John
 
You can look here:http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!126.entry

and using the Reflection example.

c# 4.0 (not out yet) will have this new "dynamic" keyword........but that's
neither here nor now.

I don't see how "dynamic" will help at all in this scenario.

Personally, for scenarios involving automated dynamic loading of
plugins, I recommend MEF:

http://mef.codeplex.com/Wiki/View.aspx?title=Guide&referringTitle=Overview

it looks a lot like dependency injection container, but it also has
neat abilities to dynamically discover new plugins, e.g. from DLLs in
a given directory (and it can sit and watch it so the plugin is loaded
at run-time the moment it is copied there, if your app is running). It
also doesn't require you to do all the layering that System.AddIn does
(In fact, you don't even need to use interfaces, though it's still
recommended). It doesn't have any specific functionality for UI, but
that should be easy to hook up.

For the record, Visual Studio 2010 editor, uses MEF as its
extensibility framework, including UI stuff.
 
Using reflection to load these DLL's, would they be able to interact with the
"core" and would the "core" be able to call methods in the DLL that are
marked public?
 
You can easily change the Interfaces in my solution to an Abstract Class.

That way, you have 1 Abstract class with (most of) the logic. And your
concretes can have the slightly different logic.

You only get one stab at inheritance with an Abstract class (aka, no
multiple inheritance).......so use it wisely.
 
Back
Top