Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# DLL's plugin-architecture

I have a program that i developed to use a basic plugin architecture. Effectively, when the program loads it uses reflection to search the directory for dll's that fit a certain interface and then loads them. It now appears that the current list of plugins is all that will be used.

Therefore, is my current practise of check the dll files still the best practise, or are there better ways to load each dll?

Thanks.

like image 665
Darren Young Avatar asked Jan 20 '11 14:01

Darren Young


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr. Stroustroupe.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

Is C programming hard?

C is more difficult to learn than JavaScript, but it's a valuable skill to have because most programming languages are actually implemented in C. This is because C is a “machine-level” language. So learning it will teach you how a computer works and will actually make learning new languages in the future easier.


2 Answers

From your question it looks like you've built (or are trying to build) your own kind of plugin architecture. Its not such a good idea since .NET already has what you're looking for.

.NET comes with 2 ways to allow plugins.

  1. System.Addin
  2. MEF - Managed Extensibility Framework

(1) System.Addin - I've barely heard/read much about it. But you can take a look at a few articles here:
System.Addin article from MSDN magazine <- Note the Year 2007
System.Addin tools and examples at Codeplex

(2) Now, MEF, MEF is just awesome! Its a great and easy way to introduce a plugin architecture into your system. MEF is also a part of Silverlight and Visual Studio 2010 uses it. I can see you want to load dlls with plugins dynamically, with MEF you can design your app in such a way the classes you package with your software can be in your own assembly (.exe) and then you can use MEF to dynamically look for dlls in the future that will have classes that you need. The whole procedure itself is very simple in MEF.

Mike Taulty has a brilliant video series on MEF

MEF Article at Codeproject - Part 1 MEF Article at Codeproject - Part 2

MEF is Open Source on Codeplex

I personally think you should go with MEF, its new, easy and even visual studio uses it, even so you can take a look at:
Choosing between MEF and MAF (System.AddIn)

Do check out other top voted questions on the mef tag at SO

like image 126
gideon Avatar answered Sep 23 '22 23:09

gideon


You can use the FileSystemWatcher class to monitor a directory for changes.

publicvoid CreateWatcher()
{
//Create a new FileSystemWatcher.
FileSystemWatcher watcher = newFileSystemWatcher();

//Set the filter to only catch DLL files.
watcher.Filter = "*.dll";

//Subscribe to the Created event.
watcher.Created += new
FileSystemEventHandler(watcher_FileCreated);

//Set the path to C:\Temp\
watcher.Path = @"C:\Temp\";

//Enable the FileSystemWatcher events.
watcher.EnableRaisingEvents = true;
}

Then it becomes a plug and play affair :)

like image 41
The_Butcher Avatar answered Sep 22 '22 23:09

The_Butcher