Writing Plugin-Based Applications

Wrapping Up

That's about it for the PluginServices.vb file. The rest of the application is pretty simple. In the Sub Main, we call the FindPlugins method and populate a list on the form. The user can select a plugin from this list, and has the opportunity to enter two numbers and run the plugin to see what it returns.

One more thing is needed however, and that is to create the class in the host application which implements the IHost interface, and provides the plugins with a way of calling methods in the host application. For the purposes of this sample, the method will simply display a message box.

I won't go in to everything else in the host application, hopefully the code will explain itself. It's worth noting, however, that while in this sample we create an instance of a plugin each time we want to perform a calculation, usually the lifetime of a plugin object would be much longer.

One more plugin

We will just write one more plugin, this time to multiply the two numbers. This one will also use the host interface to show a message box during calculation. The code is in the "Plugin 2" folder. That's about it. I've attached all the code that goes with this tutorial, feel free to use the PluginServices.vb file in your own applications. It shouldn't require any modification.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” - Martin Fowler