Dynamic Modules is a sample prototype for a WPF modular application based on the Prism Library and the Modern UI for WPF (MUI) Toolkit. It is a proof of concept for creating metro-styled, modern UI WPF applications in a plugin architecture.
A little while ago, a colleague of mine told me about a problem he had to solve. A customer asked him to develop a desktop application that presents a different set of features in accordance to which of the enterprise offices is running the software. On the one hand, I remembered how to do that from a past project where I was involved. On the other hand, there is an open source project for creating WPF applications with a modern look & feel, which I am following since a couple of years because I think it's really great.
I wondered if there is a way to solve the problem by using Prism and the open source MUI library for creating a plugin architecture, and came up with a prototype solution which I am presenting here.
- Put into a directory the desired project modules (or put them all and run a filter on loading time).
- Dynamically load the project modules from the modules folder.
- Each module exposes an entry point for an option in the main menu.
- Dynamically build the main menu from the loaded modules.
- The first option in the main menu is fixed and common for every user.
- A core module with shared services, repositories, DTOs, data model definitions, etc., is statically loaded. It can be referenced by any solution project.
Dynamic Modules are copied to a directory as part of a post-build step. These modules are not referenced in the startup project and are discovered by examining the assemblies in a directory. The module projects have the following post-build step in order to copy themselves into that directory:
xcopy "$(TargetDir)$(TargetFileName)" "$(TargetDir)modules" /y
Note that the solution is built into "..\bin" folder.
WARNING! Do not forget to build the solution (F6) before each running so the modules are copied into the modules folder.
You may find complementary information at:
- Dynamic Modules with Prism and the Modern UI for WPF Toolkit
- Modern UI for WPF (MUI) Demo project
- Modern UI for WPF Templates (Visual Studio Extension)
- Prism Samples WPF / Modularity With Unity
- On Prism's ViewModelLocator convention*
*Currently there is no need to "implement" the IView interface in the view's code-behind.