Enable dynamic library from the Internet

I am developing a project, and I have many submodules. When I create another add-on module, we need to compile the project again and deploy it. This is not very cool ...

I would like to create some logic for this to automate my work. My idea is to load the add-on module into the Blade Azure repository, and after that my project loads the add-on module and includes this add-on module in my project without compiling the entire project.

I do not know how to integrate with my existing software.

How can i do this?

+5
source share
1 answer

You have several options. The easiest, in my opinion, is to create a common interface, something like IPlugin . Add this to your remote build and let your application validate it.

 IPluginManager manager = this; // let this class implement IPluginManager Assembly assembly = Assembly.LoadFile(downloadedFilePath); foreach (Type type in assembly.GetTypes()) { foreach (Type interfaceType in type.FindInterfaces ( delegate(Type m, object filterCriteria) { return m.FullName == typeof(IPlugin).FullName; } , null ) ) { IPlugin plugin = (IPlugin)Activator.CreateInstance(interfaceType); plugin.Activate(manager); } } 

IPlugin and IPluginManager :

 public interface IPluginManager { void Foo(); } public interface IPlugin { void Activate(IPluginManager manager); } 

This code loads the downloaded assembly saved in a file into downloadedFilePath . He then finds the classes that implement IPlugin and loads them.

From there it's all yours. You can use both interfaces to add functionality to plugins and application. A class that implements IPluginManager processes all messages from and to plugins.


If you don’t like to ride on your own, you can use the MEF ( Managed Extensibility Framework ).

+1
source

All Articles