|
|||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionThis is my first English article, so excuse my horrible English. The first Time i start to develop a .NET Application i had to load a DLL dynamicly. Puh... I don't know how but i wrote a Function to do that. Next Time i need a Function to load a DLL from a Interface. Ok Copy the first Function and change the Parameters. After that i must load not only one DLL so we can have many. Ok Copy the first Function and change the Parameters. Hmm, wait a moment. There is many Space to do it in the generic way. BackgroundThe Generic way means that you have, at designtime, no Idea what objects at runtime you will work with. public static class ModuleLoader<T>
Using the codeFunctionlist: Load only one Module public static T LoadModule(Guid moduleId)
public static T LoadModule(Guid moduleId, string path)
public static T LoadModule(Guid moduleId, string path, string fileExtension)
Load a list of Modules public static List<T> LoadModuleList()
public static List<T> LoadModuleList(string path)
public static List<T> LoadModuleList(Guid moduleId, string path, string fileExtension)
When you want to load a list of Modules, i think you will use a Interface as T Example: Loads all Assemblies that implement the IPlugIn Interface in the current Directory List<IPlugIn> pluginList = ModuleLoader<IPlugIn>.LoadModuleList();
Loads a given Assembly that implement the IPlugIn Interface in the current Directory. Where pluginId the TypeGuid of the given PlugIn is. IPlugIn plugin = ModuleLoader<IPlugIn>.LoadModule(pluginId);
In the next Article i will explain how you can use the ModuleLoader with a AppDomain to load and unload at runtime.
|
||||||||||||||||||||||||||||||||||||||||