Introduce DataBase,Asp.net,JavaScript,Xml,Html,Css,Sql,Php,ASP.NET Controls,AJAX,Tools,HTML,CSS,JavaScript,Open Source Project,WPF,.Net Framework,Linq
Top Recommended Hosting

load .NET assemblies dynamicly

by the3factory 4/1/2008 8:36:00 AM

Introduction

This 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.

Background

The 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 code

Functionlist:

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);

Related posts

Sign up for PayPal and start accepting credit card payments instantly.


Powered by BlogEngine.NET 1.2.0.0