Dynamically *Unload* a Module?

Sep 3, 2008 at 5:40 PM
Is it possible to dynamically unload a module? My app has menu options to load specific modules, but I can't find an easy way to unload a module. Any help is much appreciated!
Sep 3, 2008 at 6:11 PM
[ID10T] "is it possible to dynamically unload a module?"

Yes and no....  Once an application domain loads an assembly the assembly cannot be unloaded.  However, you can unload an AppDomain and all of the modules it contains. 

Coincidently I start development on this for the CompositeWPF this evening for my http://www.CodePlex.com/SDMS project.  Preliminary research led me to this very cool "Sample - WPF Caclulator" which shows how to load and unload AppDomains.  What particularly interested me was how easily the modules within a different AppDomain were added to the main form of the parent Domain.  I think you'll find this demo very interesting.

I'm going to create a Contrib project for the CompositeWPF using the concepts taught in the http://www.CodePlex.com/clraddins project and blog on my adventures HERE.
Sep 4, 2008 at 12:46 PM
Bill / ID10T, you may also be interested in the work I've been doing with composite apps and AppDomain isolation. I have a few posts on my blog: http://kentb.blogspot.com/search/label/MAF

Sep 4, 2008 at 5:29 PM

There's already a contrib project for CompositeWPF here that you may want to hook up on:
Sep 5, 2008 at 10:58 AM
Edited Sep 5, 2008 at 11:02 AM
@kentcb, you did an excellent job explaining a complex topic; it helped make sense out of the required components and tied everything together nicely.  My thoughts are to create a MAFModuleLoader class which will utilize policies/strategies if/as required - I'd like your thoughts and any advice you might have on the topic to ensure I start coding in the right direction.   Your sample solution opened my eyes to a lot of things to include the requirement for the static Main() having a LoaderOptimizationAttribute; this attribute had me googling, which I blog about HERE.  During this adventure I stumbled upon the Pipeline Builder tool which (at a glance) seems to build the necessary infrastructure from a single contract file (and properly structured solution).  I'm going to compare the resulting output to the solution you provided in your blog.  I'll update the output source as required, using your solution as the guideline, because as you noted your Agnostic Host is "really cool".

@bsimser,  thanks!  I downloaded the latest release so that I can create a Contrib project that conforms. 
Sep 5, 2008 at 7:00 PM
Thanks Bill, I appreciate your feedback on my post. I have your post ear-marked to digest when I find some time over the weekend.

The posts on my blog are very much POCs that I have used as learning and have fed into the design and implementation of the real deal, which I am currently working on (and have made a lot of progress). I made the conscious decision to not impose any particular framework on add-ins. In fact, the only requirement is that they be discoverable with MAF. From there, they can use any framework they want, such as Prism, CAB, Windsor, whatever.

At this point, my shell (host) is dependent only upon .NET 3.5. It did not make sense to me to include a UI framework like Prism in the host at this stage. However, I have a layered design and the bottom layer (which is the only part I've completed) is UI agnostic, meaning I could use it for WPF, Winforms, Console apps or whatever. When I get to the layer that adds WPF support, it may make sense to introduce a framework such as Prism then, but not really sure yet.

I hope that makes some sense, and good luck in your Prism/MAF ventures!