If you are looking for a robust solution, look into MEF, the Managed Extensibility Framework.
If, however, you just want to load the DLLs as simple plugins, I have some code samples from my TournamentApi:
/// <summary>
/// Provides methods to load plugins from external assemblies.
/// </summary>
public static class PluginLoader
{
...
/// <summary>
/// Loads the plugins from a specified assembly.
/// </summary>
/// <param name="assembly">The assembly from which to load.</param>
/// <returns>The plugin factories contained in the assembly, if the load was successful; null, otherwise.</returns>
public static IEnumerable<IPluginFactory> LoadPlugins(Assembly assembly)
{
var factories = new List<IPluginFactory>();
try
{
foreach (var type in assembly.GetTypes())
{
IPluginEnumerator instance = null;
if (type.GetInterface("IPluginEnumerator") != null)
{
instance = (IPluginEnumerator)Activator.CreateInstance(type);
}
if (instance != null)
{
factories.AddRange(instance.EnumerateFactories());
}
}
}
catch (SecurityException ex)
{
throw new LoadPluginsFailureException("Loading of plugins failed. Check the inner exception for more details.", ex);
}
catch (ReflectionTypeLoadException ex)
{
throw new LoadPluginsFailureException("Loading of plugins failed. Check the inner exception for more details.", ex);
}
return factories.AsReadOnly();
}
}
This takes a loaded assembly and instantiates an instance of each IPluginEnumerator
in the assembly and has it return each IPluginFactory
(Abstract Factory) that it supports.
Please feel free to take a look at the source code to the TournamentApi project for the rest of the code.