Coolthing Of Theday

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Wednesday, 7 August 2013

Brian brings some Unity to using Prism and dynamically discovering and loading Modules at runtime

Posted on 16:28 by Unknown

brian lagunas - Prism: Dynamically Discover and Load Modules at Runtime

If you develop WPF applications with Prism, then you are probably already aware of the many ways in which you can load a module.  Loading a module starts with what is called a ModuleCatalog.  You can’t load a module unless it has been added to a ModuleCatalog.  Once the module has been added to a ModuleCatalog, Prism will then take care of loading the module assembly for you.  Prism even comes with a handful of module catalogs to give you flexibility in how you register your modules with your Prism application.  You can populate a module catalog from code, from XAML, with XML in an app.config, or from a directory.  Heck, you can even use a combination of all these options to populate your module catalog.

When I am giving a Prism talk at a public event or an internal lunch and learn at a company, I am sure to explain all the different ways of loading your modules and which catalog to use.  This is about the time where the questions really start getting interesting.  Of these questions, the most common is about the DirectoryModuleCatalog.  This particular catalog allows you to specify a folder path to load your modules from.  Now the interesting question… “but, what happens when a new module assembly is dropped into the folder?  Will it automatically be loaded into the app while it is running?”  That is a great question, and the answer is NO.  The DirectoryModuleCatalog does a one time scan of the directory and then loads all the modules that it finds.  If you drop a new module assembly into the directory, it will not be loaded until the application is restarted.  Now the follow-up question… “well, is it possible to dynamically discover the modules and load them from the directory as well?”  Answer; well of course it is.  If you’re using MEF, it’s easy.  If you’re using a container such as Unity, you will need to write the code to handle it yourself.  “Well, we don’t use MEF, so can you show us how?”  This is where my reply is always the same, “a simple web search (Google or Bing) should help you find what you are looking for”.

Well, it turns out, that’s not the case.  It seems that no one has blogged about or shared any code that handles the dynamic discovery and loading of modules using a DI container such as Unity.  Not that I could find, nor anyone who is asking me to show them could find.  Which leads me to this post.  I am going to show you an approach that I have used to support such a scenario.  I am actually going to give you two approaches.  One is the “Quick and Dirty” way.  Basically, I will throw together the simplest sample to achieve the goal.  Then I will show you “A Better Way” in which we will encapsulate this functionality into a custom ModuleCatalog that will handle everything for us.

...

My name is Greg and I pretend to write LOB Prism apps...

Well I am in the middle of using Prism & Unity to build a LOB app I and I ran into exactly what Brian is blogging about. I wanted to do a runtime discovery of modules and just couldn't figure out how to do it quickly enough, so gave up and just did it the hard way. Now that Brian has shown the way, I'm going to have to revisit that... :)

Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in .Net, Development, Prism, UnityApplicationBlock, WPF | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Mr. 7,000! This is my 7,000th post...
    Before this post; After; 20 visits between taking these snaps? Oh wait, that's probably me searching for past related posts....
  • "Windows Server Essentials Media Pack" (DNLA Stream, HTML5 and Dashboard Media stuff)
    Microsoft Downloads - Windows Server Essentials Media Pack This pack enables the media streaming functionality for Windows Server 2012...
  • Rad Gate Post... Get your Red Gate Post here...
    simple talk - Melanie Townsend - Get a copy of the Red Gate Post We recently put together a newspaper of some of the best articles fr...
  • Windows Management Framework 4.0 (PowerShell 4, PowerShell ISE, Management OData, WMI, etc.) now available
    Keith Hill's Blog - PowerShell 4.0 Now Available You can get PowerShell 4.0 for down level operating systems now via the WMF 4.0 d...
  • Viasfora - Your new favorite Visual Studio Text/*ML Editing Extension?
    Winterdom - Introducing Viasfora A couple of days ago, I unveiled Viasfora , my latest attempt at building a decently packaged extensi...
  • "Windows Server [2012 R2]: The Best Infrastructure to Run Linux Workloads"
    In the Cloud - What’s New in 2012 R2: Enabling Open Source Software Part 4 of a 9-part series . ... There are a lot of great s...
  • [Hardware Review] Life with Haswell... Haswell/Harris Beach Intel SDS Ultrabook Review - Part 2
    "So Greg, how's life with Haswell been?" "Pretty Sweet! (Mostly)" I've been given an opportunity to review t...
  • Fuzzy Lookup Add-In for Excel (Insert lame "Fuzzy, wuzzy was an Excel..." snip here)
    Microsoft Downloads - Fuzzy Lookup Add-In for Excel The Fuzzy Lookup Add-In for Excel performs fuzzy matching of textual data in Exce...
  • Caliburn.Micro v1.5.0 released (CM gets Tasks, Async/Await and Share/Setting for RT... and bug fixes of course)
    Caliburn.Micro - Caliburn.Micro v1.5.0 "Release Notes This release fixes many bugs. It also adds support for Task and async/a...
  • Just about everything you ever wanted to know about SQL Server Date and Time Data Types...
    CodeProject - Date and Time Data Types and Functions - SQL Server (2000, 2005, 2008, 2008 R2, 2012) Introduction It would be bette...

Categories

  • .Net
  • 3DPrinting
  • AFeedYouShouldRead
  • Agile
  • ALM
  • Amazon
  • Amiga
  • Analytics
  • Android
  • ASP.NET
  • Azure
  • BigData
  • bing
  • Blogging
  • Book
  • BookReview
  • BUILD
  • C
  • C#
  • C++
  • Career
  • Cat
  • cheatsheet
  • ClickOnce
  • Cloud
  • ComputerHardware
  • css
  • Data
  • DBA
  • DependencyInjection
  • Deployment
  • Design
  • Development
  • devops
  • DVCS
  • ebook
  • EDD
  • Education
  • EnterpriseLibrary
  • EntityFramework
  • Exchange
  • Expression
  • gadget
  • Game
  • GIT
  • Google
  • Government
  • Hadoop
  • hardware
  • HardwareReview
  • HaswellReview
  • HTML5
  • Humor
  • IE
  • IEExtension
  • IfAllElseFails
  • IIS
  • ILMerge
  • Image
  • Infographic
  • interview
  • InversionOfControl
  • Java
  • Javascript
  • Kinect
  • LightSwitch
  • LINQ
  • Linux
  • LosAngeles
  • Lucene
  • Lync
  • MEF
  • Metro
  • MicrosoftOffice
  • MicrosoftOutlook
  • Mono
  • MVC
  • MVVM
  • NetMon
  • NLP
  • NoSQL
  • NuGet
  • OData
  • OneNote
  • OpenXML
  • Paint.Net
  • Personal
  • Photosynth
  • Physics
  • portable
  • Poster
  • PowerShell
  • Preparedness
  • Presentation
  • Prism
  • PrivateCloud
  • RegEx
  • RemoteDesktop
  • Reporting
  • RIAServices
  • Science
  • ScienceFiction
  • Scratch
  • Scrum
  • ServiceBus
  • SharePoint
  • Silverlight
  • SimiValley
  • SPA
  • Space
  • SQLServer
  • Storyboard
  • Surface
  • SVG
  • SystemAdministration
  • T4
  • TeamBuild
  • TeamFoundationServer
  • TechEd
  • Training
  • TypeScript
  • UnitTesting
  • UnityApplicationBlock
  • Utility
  • Veteran
  • VirtualMachine
  • Visio
  • VisualBasic
  • VisualStudio
  • WCF
  • Web X.X
  • Webcast
  • WebFeed
  • WebMatrix
  • Windows
  • Windows7
  • Windows8
  • Windows8.1
  • WindowsHomeServer
  • WindowsLiveWriter
  • WindowsPhone
  • WindowsServer
  • WinRT
  • WiX
  • WMI
  • WOPI
  • WPF
  • XAML
  • XBox360
  • XboxOne
  • zombie

Blog Archive

  • ▼  2013 (500)
    • ►  December (12)
    • ►  November (61)
    • ►  October (65)
    • ►  September (38)
    • ▼  August (47)
      • Summer is almost over, but the Windows Phone Dev C...
      • Horton hears a Hadoop [set of icons]
      • Place your bets now on who's going to be the next ...
      • [Humor] NSA Job Application Flowchart
      • Reminder, you only have a couple days left to buy ...
      • Featuring Agile Planning and Portfolio Management ...
      • The .NET Universe Poster for 2013 is now available
      • Putting that new 3D printer to use... printing fos...
      • Wrapping your head about Azure, one infographic at...
      • Cool LA Metro Rail Ridership Visualization (and de...
      • Buying your own Mobile Launch Platform from NASA, ...
      • You can have my WP8 when you pry it from... these ...
      • [Limited time offer, open unit Sept 6th!] You know...
      • Taking the Bus to the next stop... Why you, Dev an...
      • Trie in C# - Example of prefix string search and s...
      • Avoid virtual stagnation - "INFOGRAPHIC: Top virt...
      • Free eBook #2 for the day: Dependency Injection wi...
      • Free eBook #1 of the day: Windows Azure SQL Report...
      • Paul Thurrott shares his latest Windows Phone 8 bo...
      • Fuzzy Lookup Add-In for Excel (Insert lame "Fuzzy,...
      • Oh Concierge, can you NuGet me [a related package ...
      • North by Northwest [Cadence] - Up coming casts fro...
      • Get the Getty... Getty Trust opens 4600 free (and ...
      • Free Payment icon's for your online web purchasing...
      • "The Developer Evangelist Handbook" - A Handbook f...
      • It's official, we've got a Windows 8.1 GA/release ...
      • Eight tips for the Windows Live Writer Power Blogg...
      • WPF/SilverLight IG Theme is now free from Infragis...
      • "How the heck is Hekaton part of SQL Server 2014.....
      • Target .Net 4.5.1 in VS2012? Yep, with the power o...
      • OneNote 2013 COM API XML Schema
      • 24 Hours of PASS (PASS Summit 2013 Sneak Peeks)
      • 10 Years... My blogging is now in the double digit...
      • [Humor] One-liners that only DBA's and T-SQL'ers w...
      • Hadoop Coloring Book (no kidding)
      • Channel 9 Windows Phone 8 App (Beta) now available...
      • Seeding your hardware hacking with the Seeed Open ...
      • Brian brings some Unity to using Prism and dynamic...
      • "What platform should I use when creating a WinSto...
      • Now that's an Idea [Book]! Windows 8 App Store Ide...
      • Web based Windows Phone App Studio Beta now available
      • [Book Review] "Building Interactive Queries with L...
      • Windows 8 Roaming Monitor Visual Studio 2012 Exten...
      • FEZ Game-O Emulator - Community Edition
      • Azure, PowerShell, Virtual Networks, VM's, Domains...
      • Visual Studio 2013 ALM and HOL VM now available...
      • [Book Review - Preview] "Building Interactive Quer...
    • ►  July (75)
    • ►  June (39)
    • ►  May (40)
    • ►  April (42)
    • ►  March (39)
    • ►  February (42)
Powered by Blogger.

About Me

Unknown
View my complete profile