Creating plug-ins with .NET

Started by
5 comments, last by edotorpedo 20 years, 3 months ago
Hi, I have a question: How would anyone go about creating plug-ins with c# and .NET? It want a program (in C#) using these plugins in a similar fashion as 'normal' c++ applications use dll plugins. Preferably I would like to code these plug-ins in C# as well. I know I could do this the hard way: using [DllImport] to import the win32 LoadLibrary function and do it from there. But isn't there a cleaner or easier way to do this? Thanks, Edo PS: Please do not start religious wars between [fill in your favorite programming language here] and C# with this thread. I used C++ for quite a while, before moving on to set C# as my 'primary' language. But I still use C++ when I need it (pointers, graphics etc), only this time it just has to be C#.NET [edited by - edotorpedo on January 14, 2004 7:52:17 AM] [edited by - edotorpedo on January 14, 2004 7:53:15 AM]
Edo
Advertisement
In Java and C#, you can use Reflection.

You''d define some static factory functions/classes in your
plug-in assembly (jar/dll) which can be invoked in your
application through Reflection. The name of the plug-in
would be specified in some configuration file.


Kami no Itte ga ore ni zettai naru!
神はサイコロを振らない!

Allright...thanks for the reply/

But I want my application to get a configuration file from a server (via webmethods), and then load the plug-ins specified by the configuration file. So the plug-ins should not be loaded at JIT-compile time, but during run-time.

Is this possible?

Thanks,

Edo
Edo
There are actually a couple of different ways you could approach this problem.

Here are some links regarding plugin systems in C# that should get you up and going:

I have them listed in order of relevance to your problem:

http://www.codeproject.com/csharp/plugins.asp
http://www.codeproject.com/csharp/C__Plugin_Architecture.asp


The first link I believe is the answer to what you are looking for completely. The bottom link is just supporting architecture.

Hope that helps!
oops I forgot this link:

http://msdn.microsoft.com/asp.net/using/building/components/default.aspx?pull=/library/en-us/dnaspp/html/searchforplugins.asp

I am unsure if you are going to use dynamic searching, but I use it on the server I am writing for my game and it works wonders!

Thanks imperil!

Those articles are looking quite promising. I don''t know what dynamic searching is, but here''s what I''m trying to do:

A client needs to send data to a server weekly, but which data is dependent on a configuration file which is maintained on the server. So when the client application runs, it should first get the config-file from the server. If this says it needs to run some modules it doesn''t have yet, the client needs to download those modules from an ftp-server.

If it has all the correct modules, it needs to run the code in these modules to retrieve information about the client, and the client needs to send this info to the server again, which will store the data.

Hope this doesn''t sound to vague. I have everything mentioned above already running, but now all modules are hardcoded within the client application, and I want it to be dynamic, so I can add new modules for all clients just by changing one config-file on the server.

Will let you know if I have any more problems.

Edo
Edo
quote:Original post by edotorpedo

Thanks imperil!

Those articles are looking quite promising. I don't know what dynamic searching is, but here's what I'm trying to do:

A client needs to send data to a server weekly, but which data is dependent on a configuration file which is maintained on the server. So when the client application runs, it should first get the config-file from the server. If this says it needs to run some modules it doesn't have yet, the client needs to download those modules from an ftp-server.

If it has all the correct modules, it needs to run the code in these modules to retrieve information about the client, and the client needs to send this info to the server again, which will store the data.

Hope this doesn't sound to vague. I have everything mentioned above already running, but now all modules are hardcoded within the client application, and I want it to be dynamic, so I can add new modules for all clients just by changing one config-file on the server.

Will let you know if I have any more problems.

Edo



That first link should solve your problem right away!

The MSDN link I provided later on is for dynamically searching for plugins. Basically say you in your application directory you have a folder named "plugins", you can have your application look for valid plugins and load them at runtime or when needed.

This is what it would do in your case:

Say a client connects and the server says that they need to update.

You can either tell the client to connect to an ftp and download the updated modules OR you can have the server program send the modules and update on the fly.

Now once the client has these new modules.. you would either have to get them to update a config file (or download one), or download a new EXE.. which is not what you want to have happen.

Use dynamic searching for plugins, you can just have the applicaion look in a plugins directory and automatically load the new plugin the next time the application is run.

Hope that helps, and good luck!

[edited by - Imperil on January 14, 2004 10:37:54 AM]

This topic is closed to new replies.

Advertisement