Can user built Classes be Added to Csharp Program without rebuilding??

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Hi

In the OLD COM world I was able to design COM Objects that could just be
dropped on a machine
and registered. This COM object could then be called by my pgm by a
CreateObject of the ProgID.
I would search the registry in a certain location for all the progid
that I registered and then I had access to
that code base.

Is there any way that I can minic this in dotnet???
I would like to add classes that add functionality to my program by just
dropping on a machine.

For instance say I had a calculator pgm. If I wrote it to just add and
subtract. I would like to
drop a divide class and then have that fct available to my product.

Any insight would be appreciated
Steve
 
Look at any of a number of the plugin architecture designs mentioned in
articles. It's very simple to do plugin code in C#. In fact, I've already
written 3 applications that have a plugin architecture in C#.

Here's a simple example:

http://www.codeproject.com/dotnet/PluginManagerClassBrk.asp

One of the things I don't care for in most of the samples I've seen is that
they tend to use XML files to list all the plugin DLLs.

Instead, what I usually do, is have a plugin directory that I search and
look for DLLs that expose a certain interface (using reflection). If the DLL
has the right interface, then I add it in, but that's simpy a matter of
personal preference.

Good luck.

Pete
 
Steve,

This is possible, but it's different in .NET. First, you will have to
handle the location of the assembly. For private assemblies, you can just
drop the dll in the same directory as the executable, and it will be
available to it. However, that doesn't mean that the functionality just
magically appears.

Your application has to know to look for the assembly. Once it finds
it, it can load it, but it won't be able to get any early bindings. To get
around this, you define an interface in another assembly. The two
assemblies then reference the assembly with the interface definition. The
plug in assembly (which is what you are trying to do) would implement the
interface, and the executable would then cast to that interface after the
type is loaded and created.

Hope this helps.
 
Have a look into System.Reflection namespace.
It can do what you want.
There are also articles on a variety of dotnet websites.
Have look for "adding plugin capability" or something similar.

Cheers,
Paul
 
Back
Top