<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MS Visual Studio/.NET Archives | DMC, Inc.</title>
	<atom:link href="https://static.dmcinfo.com/blog/tag/ms-visual-studio-net/feed/index.xml" rel="self" type="application/rss+xml" />
	<link></link>
	<description></description>
	<lastBuildDate>Fri, 24 Jul 2026 18:37:48 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.2</generator>

<image>
	<url>https://static.dmcinfo.com/wp-content/uploads/2025/04/site-icon-150x150.png</url>
	<title>MS Visual Studio/.NET Archives | DMC, Inc.</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Simultaneously Flash 8 ECUs with LabVIEW and Vector</title>
		<link>https://static.dmcinfo.com/blog/22287/simultaneously-flash-8-ecus-with-labview-and-vector/</link>
		
		<dc:creator><![CDATA[Cecilia Tetlow]]></dc:creator>
		<pubDate>Mon, 14 Jan 2019 12:26:17 +0000</pubDate>
				<category><![CDATA[LabVIEW]]></category>
		<category><![CDATA[Test and Measurement Automation]]></category>
		<category><![CDATA[MS Visual Studio/.NET]]></category>
		<guid isPermaLink="false">https://static.dmcinfo.com/blog/22287/simultaneously-flash-8-ecus-with-labview-and-vector-2/</guid>

					<description><![CDATA[<p>Flashing an ECU can be a time-intensive process, so it’s no wonder that automotive OEMs are looking for ways to speed up production. Luckily, Vector has released a set of C/C# API commands called vFlashStation. This library has the capability to simultaneously flash up to eight ECUs on separate communication channels. Additionally, these APIs are [&#8230;]</p>
<p>The post <a href="https://static.dmcinfo.com/blog/22287/simultaneously-flash-8-ecus-with-labview-and-vector/">Simultaneously Flash 8 ECUs with LabVIEW and Vector</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Flashing an ECU can be a time-intensive process, so it’s no wonder that automotive OEMs are looking for ways to speed up production. Luckily, <a href="https://www.vector.com/int/en/products/products-a-z/software/vflash/#c5419">Vector</a> has released a set of C/C# API commands called vFlashStation.</p>



<p class="wp-block-paragraph">This library has the capability to simultaneously flash up to eight ECUs on separate communication channels. Additionally, these APIs are compatible with several application environments, including LabVIEW.</p>



<h2 class="wp-block-heading" id="h-learn-vflashstation-api-calls">Learn vFlashStation API Calls</h2>



<p class="wp-block-paragraph">This blog explains how we were able to integrate Vector’s vFlashStation API with NI’s LabVIEW development environment to flash software to multiple ECUs at a time.</p>



<p class="wp-block-paragraph">To flash an ECU, there are five necessary commands:</p>



<ol class="wp-block-list">
<li><strong>Initialize()</strong><br>
 <br>
 <strong>Description:</strong> Synchronously initializes the vFlash library. This must be called before calling any other command.<br>
 &nbsp;</li>



<li><strong>Load Project</strong>(<strong>string</strong> <em>Path</em>, <strong>uint </strong><em>channelID</em>, <strong>out long </strong><em>projectHandle</em>)<br>
 <br>
 <strong>Description:</strong> Synchronously loads a packed project (.vflashpack) to a specific channel. The flash project contains important data such as the security seed key and necessary flashware. The packed project must be initially created using the vFlash GUI that comes with the hardware.<br>
 <br>
 <strong>Parameters:</strong><br>
 &nbsp;
 
 
<ul class="wp-block-list">
<li><strong>Path</strong>: filepath to the vFlash packed project (.vflashpack).<br>
  &nbsp;</li>



<li><strong>channelID</strong>: Channel number for the project. It must match the numbers used in the Vector Hardware Configuration screen (vFlash CAN 1, vFlash CAN 2, etc.).<br>
  &nbsp;</li>



<li><strong>projectHandle</strong>: The method will return a handle (ID) for the newly loaded project.<br>
  &nbsp;</li>
</ul>
</li>



<li><strong>Start</strong>(<strong>long </strong><em>projectHandle, </em><strong>CallbackProgressDelegate</strong> <em>progressCallback</em>, <strong>CallbackStatusDelegate</strong> <em>statusCallback</em>)<br>
 <br>
 <strong>Description:</strong> Asynchronously starts the flash process for the channel as indicated by the projectHandle.<br>
 &nbsp;
 

 
 
<p class="wp-block-paragraph"><strong>Parameters:</strong></p>



<ul class="wp-block-list">
<li><strong>projectHandle</strong>: Handle (ID) to the project to be flashed. Should have been created during the Load Project method.<br>
  &nbsp;</li>



<li><strong>progressCallback</strong>: Delegate reporting the flash progress in percent and time remaining (seconds).<br>
  &nbsp;</li>



<li><strong>statusCallback</strong>: Delegate reporting the status of the flash process (enum containing success or error information).<br>
  &nbsp;</li>
</ul>
</li>



<li><strong>Unload Project</strong>(<strong>long </strong><em>projectHandle</em>)<br>
 <br>
 <strong>Description:</strong> Synchronously unloads the project associated with the project handle.<br>
 <br>
 <strong>Parameters:</strong><br>
 &nbsp;
 
 
<ul class="wp-block-list">
<li><strong>projectHandle</strong>: ID of the associated project and channel. Should have been created during the Load Project method.<br>
  &nbsp;</li>
</ul>
</li>



<li><strong>Deinitialize</strong>()<br>
 <br>
 <strong>Description:</strong> Deinitializes the vFlash library in order to free allocated resources.</li>
</ol>



<p class="wp-block-paragraph">These are the bare bone methods required to flash an ECU through the vFlashStation API. While the other methods are not described in detail in this blog post, Vector also created other API calls to customize reporting, networks, flash attributes, and custom actions.</p>



<h2 class="wp-block-heading" id="h-create-a-c-based-wrapper-of-vflashstation-api">Create a C-Based Wrapper of vFlashStation API</h2>



<p class="wp-block-paragraph">It’s important to note that the Start API method requires two callback delegates in order to correctly query the flashing status information. This is especially important for simultaneously flashing multiple ECUs. However, LabVIEW does not currently have a way to natively access or call a callback delegate.</p>



<p class="wp-block-paragraph">The best workaround for this is to create a C-based wrapper to handle the callback delegate. In my case, I created a script using Visual Studio that referenced the vFlashStationAutomation DLL and housed my desired methods and callback delegates. The code snippet below shows how the vFlashStation API and callback delegates are utilized in my wrapper.<br>
&nbsp;</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C#</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>        public VFlashStationResult StartFlash()
        {
            VFlashStationResult startResult = VFlashStationAPI.Start(ProjectHandle, ProgressCallback, StatusCallback);
            return startResult;
        }


        /// &lt;summary>
        /// The StatusCallback handles changes of the reprogramming status.
        /// If the reprogramming process was successfully finished, the callback contains
        /// the result &lt;see cref="VFlashStationStatus.Success"/>.
        /// Otherwise the &lt;paramref name="flashStationStatus"/> contains the error code.
        /// &lt;/summary>
        /// &lt;param name="ProjectHandle">The project handle.&lt;/param>
        /// &lt;param name="flashStationStatus">The flash station status.&lt;/param>
        /// &lt;remarks>If detailed error information is required, 
        /// check &lt;see cref="VFlashStationAPI.GetLastErrorMessage"/>.&lt;/remarks>
        private void StatusCallback(long ProjectHandle, VFlashStationStatus flashStationStatus)
        {
            Status = flashStationStatus;
        }

        /// &lt;summary>
        /// The ProgressCallback contains progress information about the current
        /// reprogramming process containing the progress in percent and the
        /// estimated remaining time in seconds to finished the flash process.
        /// &lt;/summary>
        /// &lt;param name="ProjectHandle">The project handle.&lt;/param>
        /// &lt;param name="progressInPercent">The progress in percent.&lt;/param>
        /// &lt;param name="remainingTimeInSeconds">The remaining time in seconds.&lt;/param>
        private void ProgressCallback(long ProjectHandle, uint progressInPercent, uint remainingTimeInSeconds)
        {
            PercentProgress = progressInPercent;
            TimeRemaining = remainingTimeInSeconds;
        }</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">VFlashStationResult</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">StartFlash</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">        {</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #4EC9B0">VFlashStationResult</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">startResult</span><span style="color: #D4D4D4"> = </span><span style="color: #9CDCFE">VFlashStationAPI</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">Start</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">ProjectHandle</span><span style="color: #D4D4D4">, </span><span style="color: #9CDCFE">ProgressCallback</span><span style="color: #D4D4D4">, </span><span style="color: #9CDCFE">StatusCallback</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #C586C0">return</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">startResult</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">        }</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color: #6A9955">        /// </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #6A9955">        /// The StatusCallback handles changes of the reprogramming status.</span></span>
<span class="line"><span style="color: #6A9955">        /// If the reprogramming process was successfully finished, the callback contains</span></span>
<span class="line"><span style="color: #6A9955">        /// the result </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">see</span><span style="color: #6A9955"> </span><span style="color: #9CDCFE">cref</span><span style="color: #6A9955">=</span><span style="color: #CE9178">&quot;VFlashStationStatus.Success&quot;</span><span style="color: #808080">/&gt;</span><span style="color: #6A9955">.</span></span>
<span class="line"><span style="color: #6A9955">        /// Otherwise the </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">paramref</span><span style="color: #6A9955"> </span><span style="color: #9CDCFE">name</span><span style="color: #6A9955">=</span><span style="color: #CE9178">&quot;flashStationStatus&quot;</span><span style="color: #808080">/&gt;</span><span style="color: #6A9955"> contains the error code.</span></span>
<span class="line"><span style="color: #6A9955">        /// </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #6A9955">        /// </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">param</span><span style="color: #6A9955"> </span><span style="color: #9CDCFE">name</span><span style="color: #6A9955">=</span><span style="color: #CE9178">&quot;ProjectHandle&quot;</span><span style="color: #808080">&gt;</span><span style="color: #6A9955">The project handle.</span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">param</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #6A9955">        /// </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">param</span><span style="color: #6A9955"> </span><span style="color: #9CDCFE">name</span><span style="color: #6A9955">=</span><span style="color: #CE9178">&quot;flashStationStatus&quot;</span><span style="color: #808080">&gt;</span><span style="color: #6A9955">The flash station status.</span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">param</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #6A9955">        /// </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">remarks</span><span style="color: #808080">&gt;</span><span style="color: #6A9955">If detailed error information is required, </span></span>
<span class="line"><span style="color: #6A9955">        /// check </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">see</span><span style="color: #6A9955"> </span><span style="color: #9CDCFE">cref</span><span style="color: #6A9955">=</span><span style="color: #CE9178">&quot;VFlashStationAPI.GetLastErrorMessage&quot;</span><span style="color: #808080">/&gt;</span><span style="color: #6A9955">.</span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">remarks</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">private</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">void</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">StatusCallback</span><span style="color: #D4D4D4">(</span><span style="color: #569CD6">long</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">ProjectHandle</span><span style="color: #D4D4D4">, </span><span style="color: #4EC9B0">VFlashStationStatus</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">flashStationStatus</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">        {</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #9CDCFE">Status</span><span style="color: #D4D4D4"> = </span><span style="color: #9CDCFE">flashStationStatus</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">        }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A9955">        /// </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #6A9955">        /// The ProgressCallback contains progress information about the current</span></span>
<span class="line"><span style="color: #6A9955">        /// reprogramming process containing the progress in percent and the</span></span>
<span class="line"><span style="color: #6A9955">        /// estimated remaining time in seconds to finished the flash process.</span></span>
<span class="line"><span style="color: #6A9955">        /// </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #6A9955">        /// </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">param</span><span style="color: #6A9955"> </span><span style="color: #9CDCFE">name</span><span style="color: #6A9955">=</span><span style="color: #CE9178">&quot;ProjectHandle&quot;</span><span style="color: #808080">&gt;</span><span style="color: #6A9955">The project handle.</span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">param</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #6A9955">        /// </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">param</span><span style="color: #6A9955"> </span><span style="color: #9CDCFE">name</span><span style="color: #6A9955">=</span><span style="color: #CE9178">&quot;progressInPercent&quot;</span><span style="color: #808080">&gt;</span><span style="color: #6A9955">The progress in percent.</span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">param</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #6A9955">        /// </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">param</span><span style="color: #6A9955"> </span><span style="color: #9CDCFE">name</span><span style="color: #6A9955">=</span><span style="color: #CE9178">&quot;remainingTimeInSeconds&quot;</span><span style="color: #808080">&gt;</span><span style="color: #6A9955">The remaining time in seconds.</span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">param</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">private</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">void</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">ProgressCallback</span><span style="color: #D4D4D4">(</span><span style="color: #569CD6">long</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">ProjectHandle</span><span style="color: #D4D4D4">, </span><span style="color: #569CD6">uint</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">progressInPercent</span><span style="color: #D4D4D4">, </span><span style="color: #569CD6">uint</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">remainingTimeInSeconds</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">        {</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #9CDCFE">PercentProgress</span><span style="color: #D4D4D4"> = </span><span style="color: #9CDCFE">progressInPercent</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #9CDCFE">TimeRemaining</span><span style="color: #D4D4D4"> = </span><span style="color: #9CDCFE">remainingTimeInSeconds</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">        }</span></span></code></pre></div>



<p class="wp-block-paragraph">While not shown in this code snippet, I also kept each of the vFlash API calls exposed as individual public methods in my script (like the StartFlash example above). This made my application a little more flexible from the LabVIEW perspective since I could perform the tasks independently in any sequence.</p>



<p class="wp-block-paragraph">Additionally, I also created a class called <strong>ECU</strong>&nbsp;in my C# script. This gave me a great way to group the information for each of my channels and neatly dispose of them when I no longer needed them. Each class stores the data that I need such as project path, project handle, channel ID, status, etc.</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C#</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>public class ECU : IDisposable
    {
        public string ECUname { get; private set; }
        public string ProjectPath { get; private set; }
        public long ProjectHandle { get; set; }
        public uint ChannelID { get; private set; }
        public uint PercentProgress { get; private set; }
        public uint TimeRemaining { get; private set; }
        public VFlashStationStatus Status { get; private set; }
        public VFlashStationResult Result { get; private set; }

        /// &lt;summary>
        /// Generate class for each ECU. We get name, project path, and channel ID from LabVIEW
        /// &lt;/summary>
        /// &lt;param name="projectHandle">&lt;/param>
        public ECU(string Name, string projectPath, uint channelID)
        {
            ECUname = Name;
            ProjectPath = projectPath;
            ChannelID = channelID;
            TimeRemaining = 0;
            PercentProgress = 0;
        }</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">class</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">ECU</span><span style="color: #D4D4D4"> : </span><span style="color: #4EC9B0">IDisposable</span></span>
<span class="line"><span style="color: #D4D4D4">    {</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">string</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">ECUname</span><span style="color: #D4D4D4"> { </span><span style="color: #569CD6">get</span><span style="color: #D4D4D4">; </span><span style="color: #569CD6">private</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">set</span><span style="color: #D4D4D4">; }</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">string</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">ProjectPath</span><span style="color: #D4D4D4"> { </span><span style="color: #569CD6">get</span><span style="color: #D4D4D4">; </span><span style="color: #569CD6">private</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">set</span><span style="color: #D4D4D4">; }</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">long</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">ProjectHandle</span><span style="color: #D4D4D4"> { </span><span style="color: #569CD6">get</span><span style="color: #D4D4D4">; </span><span style="color: #569CD6">set</span><span style="color: #D4D4D4">; }</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">uint</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">ChannelID</span><span style="color: #D4D4D4"> { </span><span style="color: #569CD6">get</span><span style="color: #D4D4D4">; </span><span style="color: #569CD6">private</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">set</span><span style="color: #D4D4D4">; }</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">uint</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">PercentProgress</span><span style="color: #D4D4D4"> { </span><span style="color: #569CD6">get</span><span style="color: #D4D4D4">; </span><span style="color: #569CD6">private</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">set</span><span style="color: #D4D4D4">; }</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">uint</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">TimeRemaining</span><span style="color: #D4D4D4"> { </span><span style="color: #569CD6">get</span><span style="color: #D4D4D4">; </span><span style="color: #569CD6">private</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">set</span><span style="color: #D4D4D4">; }</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">VFlashStationStatus</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Status</span><span style="color: #D4D4D4"> { </span><span style="color: #569CD6">get</span><span style="color: #D4D4D4">; </span><span style="color: #569CD6">private</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">set</span><span style="color: #D4D4D4">; }</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">VFlashStationResult</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Result</span><span style="color: #D4D4D4"> { </span><span style="color: #569CD6">get</span><span style="color: #D4D4D4">; </span><span style="color: #569CD6">private</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">set</span><span style="color: #D4D4D4">; }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A9955">        /// </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #6A9955">        /// Generate class for each ECU. We get name, project path, and channel ID from LabVIEW</span></span>
<span class="line"><span style="color: #6A9955">        /// </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #6A9955">        /// </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">param</span><span style="color: #6A9955"> </span><span style="color: #9CDCFE">name</span><span style="color: #6A9955">=</span><span style="color: #CE9178">&quot;projectHandle&quot;</span><span style="color: #808080">&gt;&lt;/</span><span style="color: #569CD6">param</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">ECU</span><span style="color: #D4D4D4">(</span><span style="color: #569CD6">string</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Name</span><span style="color: #D4D4D4">, </span><span style="color: #569CD6">string</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">projectPath</span><span style="color: #D4D4D4">, </span><span style="color: #569CD6">uint</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">channelID</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">        {</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #9CDCFE">ECUname</span><span style="color: #D4D4D4"> = </span><span style="color: #9CDCFE">Name</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #9CDCFE">ProjectPath</span><span style="color: #D4D4D4"> = </span><span style="color: #9CDCFE">projectPath</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #9CDCFE">ChannelID</span><span style="color: #D4D4D4"> = </span><span style="color: #9CDCFE">channelID</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #9CDCFE">TimeRemaining</span><span style="color: #D4D4D4"> = </span><span style="color: #B5CEA8">0</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #9CDCFE">PercentProgress</span><span style="color: #D4D4D4"> = </span><span style="color: #B5CEA8">0</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">        }</span></span></code></pre></div>



<p class="wp-block-paragraph">I then compiled the script to create my own DLL, titled <strong>StartFlash.dll</strong>. Integrating my wrapper into LabVIEW was simpler since I did not need to worry about the callback delegates.</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Create-DLL-1.png" alt="Create DLL"/></figure>



<h2 class="wp-block-heading" id="h-call-dll-methods-from-labview">Call DLL Methods from LabVIEW</h2>



<p class="wp-block-paragraph">There are two ways to call functions wrapped within a DLL: a Call Library Function Node, or an Invoke Node. A Call Library Function is useful when the DLL is a C/C++ DLL, and an Invoke Node is great for C#/.NET assemblies. You can also view NI’s knowledge article, <a href="https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019Ls1SAE&amp;l=en-US"><strong>Calling a DLL from LabVIEW</strong></a>, for more details.</p>



<p class="wp-block-paragraph">In this case, we’ve created a .NET assembly so the correct option is to use the invoke nodes from the .NET palette within LabVIEW.</p>



<ol class="wp-block-list">
<li>Place a .NET Constructor Node on the block diagram to instantiate a class within the .NET assembly.<br>
 
<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Create-NET-Constructor-1.png" alt="Select .NET Constructor Node"/></figure>
</li>



<li>Select the constructor by browsing for the desired .NET assembly DLL. For this example, we need the <strong>StartFlash DLL </strong>I created earlier and my ECU class.<br>
 <br>
 You should now have a constructor node with any required inputs (Name, project path, and channel ID). Wiring controls/constants to these inputs will initialize your class data.<br>
 &nbsp;<br>
 The output of this constructor node is a reference to the newly created class. This reference can now be wired into property nodes or invoke nodes in order to read/write class data or access public methods, respectively.<br>
 &nbsp;
<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Select-Correct-DLL-1.png" alt="Browse Desired .NET Assembly"/></figure>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Configured-Constructor-Node-1.png" alt="Properly Configured Constructor Node"/></figure>
</li>



<li>Wire the class reference to the input of an invoke node. You should see it automatically adapt to the reference type wired in.
 

 

 

 

 

 

 
 
<p class="wp-block-paragraph">&nbsp;&nbsp;<br>
 &nbsp;</p>



<p class="wp-block-paragraph">The available methods will automatically be populated based on the class reference. Select the desired method from the method drop-down menu and any inputs/outputs will automatically be created.<br>
 &nbsp;</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">That’s how simple it is to access public methods within a DLL. The only thing remaining is to organize the LabVIEW application to call the vFlash methods in the proper order in order to flash up to eight ECUs at a time.<br>
 &nbsp;</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Invoke-Node-Example-1.png" alt="Example of vFlashStation API LabVIEW Call"/></figure>



<p class="wp-block-paragraph">One last piece of advice: It’s always important to properly dispose of any references open in LabVIEW. In this case, we need to dispose of our .NET class and our .NET class reference.<br>
 &nbsp;</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Dispose-References-1.png" alt="Dispose of References"/></figure>
</li>
</ol>



<p class="wp-block-paragraph"><a href="https://static.dmcinfo.com/services/test-and-measurement-automation/labview-programming" target="_self">Learn more about DMC&#8217;s LabVIEW programming experience</a>.</p>
<p>The post <a href="https://static.dmcinfo.com/blog/22287/simultaneously-flash-8-ecus-with-labview-and-vector/">Simultaneously Flash 8 ECUs with LabVIEW and Vector</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>DMC Attends Inaugural TwinCAT HMI Training</title>
		<link>https://static.dmcinfo.com/blog/22685/dmc-attends-inaugural-twincat-hmi-training/</link>
		
		<dc:creator><![CDATA[DMC]]></dc:creator>
		<pubDate>Mon, 17 Sep 2018 10:33:52 +0000</pubDate>
				<category><![CDATA[HMI and SCADA]]></category>
		<category><![CDATA[Manufacturing Automation & Intelligence]]></category>
		<category><![CDATA[PLC]]></category>
		<category><![CDATA[User Interface Design]]></category>
		<category><![CDATA[Web Application Development]]></category>
		<category><![CDATA[Beckhoff and TwinCAT]]></category>
		<category><![CDATA[HTML and CSS]]></category>
		<category><![CDATA[MS Visual Studio/.NET]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Web]]></category>
		<guid isPermaLink="false">https://static.dmcinfo.com/blog/22685/dmc-attends-inaugural-twincat-hmi-training/</guid>

					<description><![CDATA[<p>Earlier this year, DMC attended a training course on the new TwinCAT HMI at Beckhoff&#8217;s U.S. headquarters in Savage, MN. We were impressed by the flexibility and convenience offered by the platform and have already enjoyed using it on projects. Due to its unique developer-friendly design, DMC has been able to reduce development time and [&#8230;]</p>
<p>The post <a href="https://static.dmcinfo.com/blog/22685/dmc-attends-inaugural-twincat-hmi-training/">DMC Attends Inaugural TwinCAT HMI Training</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph">Earlier this year, DMC attended a training course on the new TwinCAT HMI at Beckhoff&rsquo;s U.S. headquarters in Savage, MN. We were impressed by the flexibility and convenience offered by the platform and have already enjoyed using it on projects. Due to its unique developer-friendly design, DMC has been able to reduce development time and save money for our clients. Here&rsquo;s a couple of the features of Beckhoff&rsquo;s new HMI that set it apart:</p>

<p class="wp-block-paragraph"><strong>Web-based Control and Monitoring</strong></p>

<p class="wp-block-paragraph">The most appealing aspect of Beckhoff&rsquo;s platform is that it leverages the internet to allow end users to control and monitor their PLCs from anywhere. Interfacing with industrial controllers via the internet is a common request for DMC, and the TwinCAT HMI makes this easier than ever before with integrated server- and client-side development connecting easily to the underlying PLC access. The key benefit is that a web-based HMI can be accessed from any number of different clients &ndash; a traditional monitor screen nearby the device being controlled, a tablet carried around the area by a supervisor, or even a mobile phone halfway around the world. The HMI includes a responsive grid designed to facilitate development for multiple device sizes.</p>

<figure class="wp-block-image"><img decoding="async" alt="Multiple Web Clients for TwinCAT HMI Server" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/TCHMI-Multi-Client_1.jpg"  /></figure>

<p class="wp-block-paragraph"><strong>WYSIWYG Web Page Design</strong></p>

<p class="wp-block-paragraph">As any web developer can tell you, managing the location and arrangement of content on the page can be one of the most time-consuming aspects to do manually. Development for TwinCAT gets around these issues using a What You See Is What You Get style editor, paired with other features to make life easy for developers. Selecting and arranging components is as simple as dragging them in from a menu. The HMI features dozens of prebuilt components, including commonly used displays and controls, as well as advanced charts. We walked through a demo project using several different charts, which update live when linked with the PLC data, making it very easy to display live system data of all sorts to your end users.</p>

<figure class="wp-block-image"><img decoding="async" alt="TwinCAT HMI Development in Visual Studio" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/TCHMI-VS.jpg"  /></figure>

<p class="wp-block-paragraph"><strong>Development in Visual Studio</strong></p>

<p class="wp-block-paragraph">This is a good point to bring up the ease of development afforded by the IDE. Development for the HMI is integrated directly into Visual Studio, which is very familiar to DMC from our extensive .NET development. The Visual Studio pane and menu system&rsquo;s familiarity makes navigation quick, and Beckhoff&rsquo;s custom screens are also very easy to use. Integrating development into a widely used and well-regarded editor allows engineers to develop a simple web-based HMIs for their PLCs without requiring extensive knowledge of web technologies. However, developers familiar with web technologies (like DMC) still have access to the generated results, allowing us to tailor a solution to the exact needs of our clients.</p>

<p class="wp-block-paragraph"><strong>Easy Extension and Customization</strong></p>

<p class="wp-block-paragraph">As mentioned, Beckhoff&rsquo;s existing framework controls allow for rapid development, especially for simple applications. However, the HMI is also very extensible, allowing for flexible and very custom solutions. DMC took an additional course in designing extensions for custom applications. The extensibility allows for custom Javascript interactive controls, in the case that the provided components don&rsquo;t quite fit the bill. Further, the HMI allows for custom server controls in C#, which allows us to develop connect to any system, use any library, or employ any custom code from our .NET expertise. The flexibility of these extensions, combined with the ease of creating a simple solution, makes us very excited to work on projects with this new HMI.</p>

<p class="wp-block-paragraph">Thanks to Zachary Daulton and co. at Beckhoff for hosting us and giving us a preview of the software!</p>
<p>The post <a href="https://static.dmcinfo.com/blog/22685/dmc-attends-inaugural-twincat-hmi-training/">DMC Attends Inaugural TwinCAT HMI Training</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Creating a Password Protected SDF File from an Existing SQL Database</title>
		<link>https://static.dmcinfo.com/blog/24119/creating-a-password-protected-sdf-file-from-an-existing-sql-database/</link>
		
		<dc:creator><![CDATA[DMC]]></dc:creator>
		<pubDate>Mon, 10 Jul 2017 11:30:18 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[MS Visual Studio/.NET]]></category>
		<category><![CDATA[Software Development]]></category>
		<guid isPermaLink="false">https://static.dmcinfo.com/blog/24119/creating-a-password-protected-sdf-file-from-an-existing-sql-database/</guid>

					<description><![CDATA[<p>SQL Server Compact Edition is a&#160;compact&#160;relational database&#160;produced by&#160;Microsoft&#160;for applications that run on mobile devices and desktops.&#160;Embedding these databases into a Windows&#160;application in a portable file-oriented format can be very useful.&#160; While working&#160;on a recent Windows application, DMC wanted to add an extra layer of security to our application by protecting our SQL CE database files [&#8230;]</p>
<p>The post <a href="https://static.dmcinfo.com/blog/24119/creating-a-password-protected-sdf-file-from-an-existing-sql-database/">Creating a Password Protected SDF File from an Existing SQL Database</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">SQL Server Compact Edition is a&nbsp;compact&nbsp;relational database&nbsp;produced by&nbsp;Microsoft&nbsp;for applications that run on mobile devices and desktops.&nbsp;Embedding these databases into a Windows&nbsp;application in a portable file-oriented format can be very useful.&nbsp;</p>



<p class="wp-block-paragraph">While working&nbsp;on a recent Windows application, DMC wanted to add an extra layer of security to our application by protecting our SQL CE database files with a password.&nbsp;Although the process of creating a&nbsp;“.SDF” file from an existing database is simple, there are a few additional steps that are required when adding password protection.&nbsp;</p>



<p class="wp-block-paragraph">After finding no good resources on this process anywhere on the internet, I decided to document the process here.</p>



<p class="wp-block-paragraph">This walkthrough will use the SQL Server Compact Toolbox for Runtime 4.0 which <a href="https://marketplace.visualstudio.com/items?itemName=ErikEJ.SQLServerCompactSQLiteToolbox" type="link" id="https://marketplace.visualstudio.com/items?itemName=ErikEJ.SQLServerCompactSQLiteToolbox">you can download</a>.</p>



<h2 id="h-step-1-create-an-empty-password-protected-sdf-file" class="wp-block-heading">Step 1: Create an empty, password protected .SDF file</h2>



<p class="wp-block-paragraph">Right click&nbsp;on <strong>No SQL Compact Data Connections Found</strong>&nbsp;and select&nbsp;<strong>Add SQL Server Compact 4.0 Connection…</strong></p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Create-New-SDF-File-1_1.jpg" alt="Create new .SDF file "/></figure>



<p class="wp-block-paragraph">A small window will pop up&nbsp;where you will enter your desired password.&nbsp;After your password has been entered, click <strong>Create</strong>&nbsp;at the top of the window where you will name your new .SDF file.&nbsp;</p>



<p class="wp-block-paragraph">Finally, click <strong>Close</strong>&nbsp;at the bottom of the window in order for your new empty .SDF to be created.</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Create-New-SDF-File-2_1.jpg" alt="Assign .SDF file password"/></figure>



<p class="wp-block-paragraph">Your password protected .SDF file will now appear on the left-hand side in the main window of the toolbox.&nbsp;</p>



<h2 id="h-step-2-export-your-existing-sql-server-database-to-a-sqlce-file" class="wp-block-heading">Step 2: Export your existing SQL Server Database to a .SQLCE file.</h2>



<p class="wp-block-paragraph">Right click on <strong>SQL Server Compact Data Connections</strong>&nbsp;and select <strong>Script SQL Server Database Schema and Data…</strong></p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Export-From-SQL-Server-to-sqlce_1.jpg" alt="Export SQL database to .SQLCE "/></figure>



<p class="wp-block-paragraph">A window will popup that requires you to enter information to connect to your existing SQL Server DB.&nbsp;</p>



<p class="wp-block-paragraph">Enter the <strong>server name</strong> and select the <strong>database name</strong> from the drop-down menu.&nbsp;</p>



<p class="wp-block-paragraph">Finally, click <strong>Ok</strong>&nbsp;and name your new .SQLCE file.&nbsp;</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Export-From-SQL-Server-to-sqlce-2_1.jpg" alt="Export existing SQL Server database to SQLCE"/></figure>



<p class="wp-block-paragraph">In the next popup, select the&nbsp;tables from your existing database which you want to export by clicking the appropriate check boxes. This will vary based on your application.&nbsp;</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Export-From-SQL-Server-to-sqlce-3_1.jpg" alt="Select tables to export to .SDF"/></figure>



<h2 id="h-step-3-move-the-exported-data-into-your-new-password-protected-sdf" class="wp-block-heading">Step 3: Move the exported data into your new password protected SDF.</h2>



<p class="wp-block-paragraph">Next, right-click on your new password protected DB that has been created on the left side of the toolbox and select <strong>Open SQL Editor</strong>”.&nbsp;</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Import-SQL-Data-Into-SDF-File_1.jpg" alt="Import SQL data from SQLCE file"/></figure>



<p class="wp-block-paragraph">An editor will open&nbsp;up on the main part of the screen.</p>



<p class="wp-block-paragraph">Select <strong>Open</strong>&nbsp;and navigate to the location of the .SQLCE file you just created.</p>



<p class="wp-block-paragraph">&nbsp;</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Import-SQL-Data-Into-SDF-File-2_1.jpg" alt="Navigate to existing SQLCE file"/></figure>



<p class="wp-block-paragraph">Once this step is completed, you will see text commands opened in the main window.&nbsp;</p>



<p class="wp-block-paragraph">Click <strong>Execute</strong>&nbsp;and wait for this operation to complete.&nbsp;Once completed, you will be able to verify the operation was successful by expanding <strong>Tables</strong>&nbsp;in the left-hand side tree view and checking that the correct tables have been added.</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Import-SQL-Data-Into-SDF-File-3_1.jpg" alt="Execute operation and verify populated .SDF file"/></figure>



<p class="wp-block-paragraph">SQL Server Database has now successfully been moved into a password protected .SDF file!</p>



<p class="wp-block-paragraph">As a final note, when using this in your Windows application you must enter the .SDF’s password. Microsoft provides information about <a href="https://msdn.microsoft.com/en-us/library/ms171741(v=SQL.105).aspx" type="link" id="https://msdn.microsoft.com/en-us/library/ms171741(v=SQL.105).aspx">how to accomplish this</a>. </p>



<p class="wp-block-paragraph"><strong><a href="https://static.dmcinfo.com/services/embedded-development-and-embedded-programming" target="_blank">Learn more about DMC&#8217;s Custom Software &amp; Hardware development services.</a>&nbsp;</strong></p>
<p>The post <a href="https://static.dmcinfo.com/blog/24119/creating-a-password-protected-sdf-file-from-an-existing-sql-database/">Creating a Password Protected SDF File from an Existing SQL Database</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>The Revit API: Creating Your First Add-In</title>
		<link>https://static.dmcinfo.com/blog/24963/the-revit-api-creating-your-first-add-in/</link>
		
		<dc:creator><![CDATA[Christopher Olsen]]></dc:creator>
		<pubDate>Thu, 03 Nov 2016 08:17:01 +0000</pubDate>
				<category><![CDATA[Application Development]]></category>
		<category><![CDATA[MS Visual Studio/.NET]]></category>
		<category><![CDATA[Software Development]]></category>
		<guid isPermaLink="false">https://static.dmcinfo.com/blog/24963/the-revit-api-creating-your-first-add-in/</guid>

					<description><![CDATA[<p>Lately, I&#8217;ve gotten reacquainted with an old friend of mine: the Revit API. Revit is an incredible piece of architectural software from Autodesk, and one of its features is the ability to expand its functionality through the use of add-ins. Revit add-in development is now one of the many services that we&#8217;re able to offer [&#8230;]</p>
<p>The post <a href="https://static.dmcinfo.com/blog/24963/the-revit-api-creating-your-first-add-in/">The Revit API: Creating Your First Add-In</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Lately, I&#8217;ve gotten reacquainted with an old friend of mine: the Revit API. Revit is an incredible piece of architectural software from Autodesk, and one of its features is the ability to expand its functionality through the use of add-ins. Revit add-in development is now one of the many services that we&#8217;re able to offer here at DMC, and I&#8217;d like to celebrate that fact by sharing an article about how to get started with Revit add-in development.</p>



<p class="wp-block-paragraph">First of all, this article assumes you know/have the following things:</p>



<ol class="wp-block-list">
<li>Intermediate C# and .NET development experience or knowledge</li>



<li>A license for Revit (preferably 2013 or later) so you can actually test your add-in</li>



<li>A license for Visual Studio (I&#8217;ll be using 2015 for this example). You can develop Revit macros using Revit’s built-in code editor, but developing add-ins (external commands and external applications) pretty much requires Visual Studio.</li>
</ol>



<p class="wp-block-paragraph">The first thing you&#8217;ll want to do is set up your development machine. I chose to use a virtual machine (VM) running Windows 8, for reasons that are beyond the scope of this article. Make sure you check the system requirements for the version of Revit that you&#8217;re developing for. Install Revit and your chosen version of Visual Studio, and you&#8217;re ready to get started.</p>



<p class="wp-block-paragraph">To create a new Revit add-in, open up Visual Studio and start a new Class Library project.</p>



<p class="wp-block-paragraph">Visual Studio is kind enough to provide us with a class, named “Class1.cs”.</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/RevitAPITutorial_4.png" alt="The class that will hold our Revit external command"/></figure>



<p class="wp-block-paragraph">Either rename it, or delete it and replace it with another class (.cs) file, and make sure the new class is named something that makes sense. I’m naming mine “RevitTutorialExternalCommand”. Once that’s done, we’re going to make our new class implement the interface “IExternalCommand”.</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/RevitAPITutorial_5.png" alt="Implementing the Revit IExternalCommand interface"/></figure>



<p class="wp-block-paragraph">As you probably know, that squiggly red underline means Visual Studio doesn&#8217;t recognize that reference. This is because IExternalCommand is an interface from the Revit API libraries. So to use it, we&#8217;ll have to add a reference in our project to the Revit API dlls. You can find these in the directory where you installed Revit. The files we&#8217;re looking for are RevitAPI.dll and RevitAPIUI.dll. These are the two libraries that you&#8217;ll use most often when developing add-ins for Revit.</p>



<p class="wp-block-paragraph">Once we&#8217;ve added references in our project to these files, we can add the line:</p>



<p class="wp-block-paragraph">using Autodesk.Revit.UI;</p>



<p class="wp-block-paragraph">to our class file.</p>



<p class="wp-block-paragraph">Now we still have the red squiggly underline; as you probably guessed, Visual Studio now recognizes the interface name, but it’s warning us that we’re not correctly implementing the interface. In order for our class to implement it, we have to add the Execute method to the class. This method has the following signature:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C#</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>public Result Execute(
    ExternalCommandData commandData,
    ref string message,
    ElementSet elements)</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">Result</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">Execute</span><span style="color: #D4D4D4">(</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #4EC9B0">ExternalCommandData</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">commandData</span><span style="color: #D4D4D4">,</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #569CD6">ref</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">string</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">message</span><span style="color: #D4D4D4">,</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #4EC9B0">ElementSet</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">elements</span><span style="color: #D4D4D4">)</span></span></code></pre></div>



<p class="wp-block-paragraph">The access modifier has to be public in order for Revit to be able to run our add-in. This method essentially serves as the entry point for your add-in – this is the equivalent of “public static void Main()”. There’s one more thing we should do before actually writing code – add an attribute that determines the transactional behavior of the external command. This attribute is in the namespace Autodesk.Revit.Attributes, so you’ll want to add that to your using statements. Revit transactions are outside the scope of this article, but the short version is that anything your add-in does to change the file that it’s working with has to be done within the scope of a transaction, so the TransactionMode enum that we supply to the Transaction attribute allows us to decide whether a transaction is automatically wrapped around our entire add-in, or whether we have to manually start and commit Transactions. It’s usually a good idea to use Manual, so that’s what I’m showing here.</p>



<p class="wp-block-paragraph">Finally, let’s write some code to make this add-in actually DO something. We’ll keep it simple for this first tutorial: we’ll just display a message box for the user.</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/RevitAPITutorial_12.png" alt="Showing a TaskDialog in Revit API"/></figure>



<p class="wp-block-paragraph">In the above image, you can see I&#8217;ve used a class called TaskDialog&#8217;s &#8220;Show&#8221; method, and passed it two strings as its parameters. The first parameter is the &#8220;title&#8221; displayed at the top of the message box. The second parameter is the content text of the message box. At the end of our Execute method, we return an Autodesk.Revit.UI.Result, an enum with three possible values: &#8220;Cancelled&#8221;, &#8220;Succeeded&#8221;, and &#8220;Failed&#8221;. We&#8217;ll return Succeeded for now.</p>



<p class="wp-block-paragraph">Finally, we&#8217;ll build our solution, start Revit, and try it out.</p>



<p class="wp-block-paragraph">But wait, there&#8217;s a problem&#8230; When we have add-ins loaded, there&#8217;s supposed to be an &#8220;Add-ins&#8221; menu tab at the top, right next to &#8220;Modify&#8221;. You can see in the above picture that it&#8217;s not there. This is because we haven&#8217;t actually deployed our add-in so that it can be loaded by Revit. We need to do two things to make this happen:&nbsp;</p>



<ol class="wp-block-list">
<li>Write an add-in file (an XML file with a &#8220;.addin&#8221; extension) that Revit reads when it starts up in order to determine which add-ins are to be loaded</li>



<li>Build our project to produce a dll file, and place it somewhere accessible (we&#8217;ve already done this one)</li>
</ol>



<p class="wp-block-paragraph">Let&#8217;s go ahead and write that .addin file. You can do this using Notepad, Notepad++, or any other text editor. When creating the file, you need to put it in the add-ins folder for your targeted version of Revit, which can be found at C:\Users\[YOUR USERNAME]\AppData\Roaming\Autodesk\Revit\Addins\[YOUR REVIT VERSION YEAR]. So for me, it&#8217;s C:\Users\Christopher Olsen\AppData\Roaming\Autodesk\Revit\Addins\2014. The AppData folder is usually hidden by default, so you&#8217;ll have to make sure Windows Explorer is configured to show hidden files and folders.</p>



<p class="wp-block-paragraph">&nbsp;</p>



<p class="wp-block-paragraph">As mentioned before, this .addin file is in XML format.</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/RevitAPITutorial_14.png" alt="A sample Revit .addin manifest file"/></figure>



<p class="wp-block-paragraph">Our root element here is the RevitAddIns tag. Within this tag, you&#8217;ll place one or more Addin tags (yes, you can use one file to specify multiple add-ins for Revit to load). The &#8220;Type&#8221; attribute on the Add-in tag is for specifying what kind of add-in this is. The two most popular options are &#8220;Command&#8221; and &#8220;Application&#8221;. Since we&#8217;ve written an external command (as indicated by the fact that we used the IExternalCommand interface), we&#8217;ll use the &#8220;Command&#8221; value for this attribute.</p>



<p class="wp-block-paragraph">&nbsp;</p>



<p class="wp-block-paragraph">Nested inside the AddIn tag, we have several important elements. The Text tag is where we specify the display name for our add-in in the &#8220;External Commands&#8221; drop-down menu in Revit. The Assembly tag must contain the file path to the dll for our add-in &#8211; in this example, I&#8217;ve pointed it toward the dll file in my project&#8217;s obj\Debug folder in order to make testing and debugging easier. AddInId is essentially the ID of your add-in, and must be unique for a session of Revit &#8211; the best way to do this is to generate a new GUID in visual studio (you can do this by going to the Tools menu, and clicking on &#8220;Create GUID&#8221;. You don&#8217;t have to put this GUID in your code somewhere, but it&#8217;s common practice to place it in a comment right above your class definition.</p>



<p class="wp-block-paragraph">Next, we have the FullClassName tag, which must contain the namespace and class name for your external command. The VendorID tag is required, and is supposed to be unique for a given session of Revit &#8211; Autodesk recommends using the url of your company&#8217;s website. Finally, VendorDescription is a more verbose description of your company &#8211; if your external command throws an unhandled exception, Revit will display an error message on screen that ends with &#8220;For more info, contact this knucklehead that developed the add-in: [VendorDescription]&#8221;. I&#8217;ve paraphrased the actual text of the error message, for comical effect.</p>



<p class="wp-block-paragraph">&nbsp;</p>



<p class="wp-block-paragraph">And that&#8217;s it. There are many more things we can specify in that .addin file, but these are the core ones you&#8217;ll really want to use. Other tags you can add to this file include the path to an image that will be displayed for your add-in in the external command drop-down menu. For a full run-down, check out the table on Autodesk&#8217;s <a href="https://www.revitapidocs.com/" target="_blank" rel="noreferrer noopener">knowledge base website</a>.</p>



<p class="wp-block-paragraph">&nbsp;</p>



<p class="wp-block-paragraph">Now, if we open Revit, we see that the &#8220;Add-Ins&#8221; tab has been added, and clicking on the &#8220;External Tools&#8221; drop-down shows us our add-in. If we click on it, our external command&#8217;s &#8220;Execute&#8221; method runs, and we get our message box.</p>



<p class="wp-block-paragraph">Now that we’ve got the super basic stuff out of the way, we can turn our attention to doing something meaningful in a Revit add-in. In my next blog post, we’ll go over how we can have our user select elements, and how we can then perform operations on those elements.</p>



<p class="wp-block-paragraph"><a href="https://static.dmcinfo.com/services/application-development/pc-application-development" target="_blank">Learn more about how DMC can help you develop custom software.</a></p>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://static.dmcinfo.com/blog/24963/the-revit-api-creating-your-first-add-in/">The Revit API: Creating Your First Add-In</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>6 Easy Steps to Get Started with MVC Module Development in DNN 8</title>
		<link>https://static.dmcinfo.com/blog/25071/6-easy-steps-to-get-started-with-mvc-module-development-in-dnn-8/</link>
		
		<dc:creator><![CDATA[DMC]]></dc:creator>
		<pubDate>Fri, 14 Oct 2016 12:37:43 +0000</pubDate>
				<category><![CDATA[Web Application Development]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C# .NET Application Development]]></category>
		<category><![CDATA[Dot Net Nuke]]></category>
		<category><![CDATA[HTML and CSS]]></category>
		<category><![CDATA[MS Visual Studio/.NET]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Web]]></category>
		<guid isPermaLink="false">https://static.dmcinfo.com/blog/25071/6-easy-steps-to-get-started-with-mvc-module-development-in-dnn-8/</guid>

					<description><![CDATA[<p>In the beginning of the year,&#160;DNN (formerly DotNetNuke) was updated to support MVC modules. MVC is the latest version of ASP.NET in which the Model-View-Controller paradigm is at the core.&#160;This article won&#8217;t be a look into what MVC is or a comparison with WebForms, but instead will give a quick guide into starting DNN MVC [&#8230;]</p>
<p>The post <a href="https://static.dmcinfo.com/blog/25071/6-easy-steps-to-get-started-with-mvc-module-development-in-dnn-8/">6 Easy Steps to Get Started with MVC Module Development in DNN 8</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">In the beginning of the year,&nbsp;DNN (formerly DotNetNuke) was updated to support MVC modules. MVC is the latest version of ASP.NET in which the Model-View-Controller paradigm is at the core.&nbsp;This article won&#8217;t be a look into what MVC is or a comparison with WebForms, but instead will give a quick guide into starting DNN MVC module development.</p>



<p class="wp-block-paragraph">While there are some guides available that give you similar information, I found it a bit difficult to get started developing MVC modules in DNN. For reference, the articles I used are at the bottom of this blog.</p>



<p class="wp-block-paragraph">Here&#8217;s an overview of the steps we&#8217;ll take to get started.</p>



<ol class="wp-block-list">
<li><a href="#prerequisites">Prerequisites</a></li>



<li><a href="#templates">Templates</a></li>



<li><a href="#setup">Setup</a></li>



<li><a href="#build">Build</a></li>



<li><a href="#installation">Installation</a></li>



<li><a href="#next-steps">Next Steps</a></li>



<li><a href="#references">References</a></li>
</ol>



<h2 id="prerequisites" class="wp-block-heading">1. Prerequisites</h2>



<p class="wp-block-paragraph">For this quick start, you&#8217;ll need a few things before we can dive in.</p>



<p class="wp-block-paragraph">First, you&#8217;ll need to have Visual Studio 2015 installed. The express editions have been reported to be incompatible with the templates we&#8217;ll be using later, but this may not be true by the time you&#8217;re reading this.</p>



<p class="wp-block-paragraph">Next, you&#8217;ll need to have IIS (Internet Information Services) setup with a local installation of DNN (version 8 or higher). There are many tutorials on how to do this around the web. You&#8217;ll need to install IIS and&nbsp;Microsoft SQL Server, then you can install DNN by downloading the latest _install.zip from <a href="https://github.com/dnnsoftware/Dnn.Platform/releases" target="_blank">DNN&#8217;s GitHub releases</a>.</p>



<p class="wp-block-paragraph">Once those are all set up, you&#8217;re ready to go.</p>



<h2 id="templates" class="wp-block-heading">2. Templates</h2>



<p class="wp-block-paragraph">You <em>could&nbsp;</em>create a module from scratch. But why would you do that when a DNN expert created templates for you to use? <a href="https://marketplace.visualstudio.com/items?itemName=Chris-Hammond.DotNetNukeDNNDevelopmentProjectTemplates" target="_blank" rel="noreferrer noopener">Download the templates from the Visual Studio Gallery</a>&nbsp;and run through the installation procedure.</p>



<h2 id="setup" class="wp-block-heading">3. Setup</h2>



<p class="wp-block-paragraph">Now that everything is set up, we can actually dive into creating the module.&nbsp;</p>



<p class="wp-block-paragraph">In Visual Studio, select File -&gt; New -&gt; Project</p>



<p class="wp-block-paragraph">In the New Project window, select Templates -&gt; Visual C# -&gt; DotNetNuke and you&#8217;ll see a listing of the types of projects the templates have provided.</p>



<p class="wp-block-paragraph">To create an MVC module, we&#8217;ll select DotNetNuke 8 C# DAL2 MVC Module. There are three other fields we must configure: Name, Location, and Solution name.</p>



<p class="wp-block-paragraph"><strong>Name: </strong>Enter a name for your project (it&#8217;s best not to use any spaces or special characters for this)</p>



<p class="wp-block-paragraph"><strong>Location:&nbsp;</strong>This is important to point this to the correct folder in DNN: /DesktopModules/MVC/.&nbsp;Depending on your installation directory, the folder should be something like C:\Dev\Projects\DMC_Website\Alpha\DesktopModules\MVC\ where &#8220;Alpha&#8221; is the root of your DNN installation.</p>



<p class="wp-block-paragraph"><strong>Solution name:</strong>&nbsp;We&#8217;re not actually going to be using this field. Uncheck&nbsp;the box on the right that says &#8220;Create directory for solution&#8221; and the solution name textbox will be greyed out.</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/2016-10-28-12_40_42-New-Project.png" alt="Configuration of the DotNetNuke 8 C# DAL2 MVC Module Visual Studio Project"/></figure>



<p class="wp-block-paragraph">Confirm your settings look similar to mine and then click OK.</p>



<p class="wp-block-paragraph">A Project Setup Wizard dialog box will appear asking for some project information. Many of these are self explanatory, so I will only address the two that are a bit tricky.</p>



<p class="wp-block-paragraph"><strong>Namespace: </strong>Whatever namespace you want your module to live in. The templates will automatically include your project name in the namespace, so no need to enter it here.&nbsp;Make sure you include the last period. E.g. DMC.</p>



<p class="wp-block-paragraph"><strong>Local Dev URL:&nbsp;</strong>By default this is set up to point to dnndev.me, which is actually set up to point back to 127.0.0.1 (your localhost). What you enter here depends on what settings you&#8217;ve set your DNN install up with. For my installation, I access my local DNN install through http://localhost./ Therefore, I am going to enter localhost as my Local Dev URL.</p>



<p class="wp-block-paragraph">Initial values</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/2016-10-14-12_49_25-Project-Setup-Wizard.png" alt="DNN Template Setup Wizard Initial Values"/></figure>



<p class="wp-block-paragraph">Updated values (note: the owner website field includes https:// but the textbox isn&#8217;t large enough to display it. Be sure to include it in your URL.)</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/2016-10-28-12_42_14-Project-Setup-Wizard.png" alt="DNN Template Setup Wizard Updated Values"/></figure>



<p class="wp-block-paragraph">Once all fields have been complete, click OK.</p>



<h2 id="build" class="wp-block-heading">4. Build</h2>



<p class="wp-block-paragraph">Now that the initial project setup is complete, you&#8217;ll be presented with a web page in Visual Studio that says * Important *. These are steps that you should&nbsp;<strong>read carefully</strong>&nbsp;and follow to ensure your project will work correctly. I&#8217;ll provide a quick overview of these steps in case the original wording is confusing for anyone.</p>



<p class="wp-block-paragraph">First, check IIS to see if any of your folders were converted to virtual directories or applications. To do this, open IIS, expand your site&#8217;s dropdown and check what icon is displayed next to your DesktopModules folder or the MVC folder inside of the DesktopModules folder. If it&#8217;s anything other than a yellow folder, right click it and click remove.</p>



<p class="wp-block-paragraph">Next, in Visual Studio, right click and delete the web.config files that are in the solution.</p>



<p class="wp-block-paragraph">You can now build the module! change the solution configuration dropdown from Debug to Release and then select Build -&gt; Build</p>



<p class="wp-block-paragraph">You&#8217;ll get an install .zip file in your module&#8217;s install/ directory.</p>



<h2 id="installation" class="wp-block-heading">5. Installation</h2>



<p class="wp-block-paragraph">Now, in DNN, go to Hosts -&gt; Extensions and click Install Extension, selecting your install .zip file that you previously built.</p>



<p class="wp-block-paragraph">If everything goes well, then the module is now installed and can be placed on any page.</p>



<h2 id="next-steps" class="wp-block-heading">6. Next Steps</h2>



<p class="wp-block-paragraph">Once you&#8217;ve dragged the module into a page, you&#8217;ll see a demo application that includes multiple views, database interaction, and more. Simply build the project in debug mode to automatically copy the new DLL to the /bin folder.</p>



<h2 id="references" class="wp-block-heading">7. References</h2>



<ul class="wp-block-list">
<li><a href="https://www.chrishammond.com/tag/dotnetnuke" type="link" id="https://www.chrishammond.com/tag/dotnetnuke" target="_blank" rel="noreferrer noopener">Chris Hammond&#8217;s DNN posts</a></li>



<li><a href="https://dnncommunity.org/blogs" type="link" id="https://dnncommunity.org/blogs" target="_blank" rel="noreferrer noopener">DNN Community Blogs</a></li>



<li><a href="https://www.dnnsoftware.com/docs/developers/mvc-modules/mvc-module-development.html" type="link" id="https://www.dnnsoftware.com/docs/developers/mvc-modules/mvc-module-development.html" target="_blank" rel="noreferrer noopener">DNN MVC Module Development</a></li>
</ul>



<p class="wp-block-paragraph">While you&#8217;re here, check out DMC&#8217;s <a href="/services/application-development/web-application-development">Web Application Development</a> and <a href="/services/application-development/web-application-development/aspnet-and-aspnet-mvc">ASP.NET &amp; ASP.NET MVC Development</a> services so we can get started on your next DNN MVC module!</p>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://static.dmcinfo.com/blog/25071/6-easy-steps-to-get-started-with-mvc-module-development-in-dnn-8/">6 Easy Steps to Get Started with MVC Module Development in DNN 8</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>A Properly Pleasing Primer Tutorial for WPF Prism &#8211; Part 3:  Modules</title>
		<link>https://static.dmcinfo.com/blog/25145/a-properly-pleasing-primer-tutorial-for-wpf-prism-part-3-modules/</link>
		
		<dc:creator><![CDATA[DMC]]></dc:creator>
		<pubDate>Mon, 03 Oct 2016 14:56:43 +0000</pubDate>
				<category><![CDATA[PC Application Development]]></category>
		<category><![CDATA[C# .NET Application Development]]></category>
		<category><![CDATA[MS Visual Studio/.NET]]></category>
		<guid isPermaLink="false">https://static.dmcinfo.com/blog/25145/a-properly-pleasing-primer-tutorial-for-wpf-prism-part-3-modules/</guid>

					<description><![CDATA[<p>In Part 2 of this series, I introduced the Shell and the Bootstrapper components of a Prism application. The stage is set. The crew&#8217;s in place. It&#8217;s time for Lights! Camera! Action! But first, we need to hire some actors. Modules To quote the Prism documentation itself: A module is a logical collection of functionality [&#8230;]</p>
<p>The post <a href="https://static.dmcinfo.com/blog/25145/a-properly-pleasing-primer-tutorial-for-wpf-prism-part-3-modules/">A Properly Pleasing Primer Tutorial for WPF Prism &#8211; Part 3:  Modules</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">In <a href="https://static.dmcinfo.com/latest-thinking/blog/id/9295/a-properly-pleasing-prism-primer--part-2-the-shell-and-bootstrapper">Part 2</a> of this series, I introduced the <strong>Shell</strong> and the <strong>Bootstrapper</strong> components of a Prism application. The stage is set. The crew&#8217;s in place. It&#8217;s time for Lights! Camera! Action! But first, we need to hire some actors.</p>



<h2 class="wp-block-heading" id="h-modules"><span style="color:#1F4D78;">Modules</span></h2>



<p class="wp-block-paragraph">To quote the Prism documentation itself:</p>



<p class="wp-block-paragraph"><em>A module is a logical collection of functionality and resources that is packaged in a way that can be separately developed, tested, deployed, and integrated into an application.</em></p>



<p class="wp-block-paragraph">All modules contain a central class responsible for initialization of the module and integration of it into the application. This class implements the <strong>IModule</strong> interface, which consists of one method:&nbsp;<strong>Initialize()</strong>. Typically, this method and a constructor are the only methods needed for this class, but I&#8217;ll share more on that in a bit.</p>



<p class="wp-block-paragraph">Before we start making our modules, we should probably decide how we want Prism to know where to find them. This is where the Module Catalog comes in.</p>



<h2 class="wp-block-heading" id="h-the-module-catalog"><span style="color:#1F4D78;">The Module Catalog</span></h2>



<p class="wp-block-paragraph">In a composite application, modules must be discovered and loaded at run time by the host application (the <strong>Shell</strong> in Prism). Prism accomplishes this through a module catalog which specifies the modules to load, when to load them and in what order. There are several choices for filling the module catalog:</p>



<ul class="wp-block-list">
<li>Registering modules in code</li>



<li>Registering modules in XAML</li>



<li>Registering modules in a configuration file</li>



<li>Discovering modules in a local directory on disk</li>



<li>Derive from ModuleCatalog class to create your own custom module catalog behavior</li>
</ul>



<p class="wp-block-paragraph">Which mechanism you use depends on the needs of your application&nbsp;(there&#8217;s also nothing stopping you from using more than one mechanism if you are so inclined). Each module catalog class implements the <strong>IModuleCatalog</strong> interface. For this application we will use directory discovery (via the <strong>DirectoryModuleCatalog</strong> class), but a brief description of the other methods follows.</p>



<h4 class="wp-block-heading" id="h-registering-modules-in-code"><span style="color:#1F4D78;">Registering Modules in Code</span></h4>



<p class="wp-block-paragraph"><span style="font-size:11.0pt;line-height:107%;
font-family:&quot;Calibri&quot;,sans-serif;mso-ascii-theme-font:minor-latin;mso-fareast-font-family:
Calibri;mso-fareast-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:&quot;Times New Roman&quot;;mso-bidi-theme-font:minor-bidi;
mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA">The <strong>ModuleCatalog</strong> class is the most basic <strong>IModuleCatalog</strong> implementation. It is used to programmatically register modules by specifying each module class type. You can also specify properties on each module such as the name, initialization mode, other module dependencies and the loading state. </span></p>



<p class="wp-block-paragraph"><span style="font-size:11.0pt;line-height:107%;
font-family:&quot;Calibri&quot;,sans-serif;mso-ascii-theme-font:minor-latin;mso-fareast-font-family:
Calibri;mso-fareast-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:&quot;Times New Roman&quot;;mso-bidi-theme-font:minor-bidi;
mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA">To register a module, call the <strong>AddModule() </strong>method of the <strong>ModuleCatalog</strong> class. This is typically done in an override of the <strong>Bootstrapper</strong> method <strong>ConfigureModuleCatalog()</strong>. With this approach, you can use conditional logic to determine which modules should be included in your application. The modules added in code are referenced by the application rather than being loaded at runtime like other methods. However, unless you want to provide a direct reference in your application to each module’s assembly, thereby giving the <strong>Shell</strong> project knowledge of what modules exist (ideally the <strong>Shell</strong> shouldn’t know anything about what modules are out there), you will have to use reflection in your <strong>Bootstrapper</strong> method to provide the fully qualified type name and location of the assembly that contains the module.</span></p>



<p class="wp-block-paragraph"><span style="font-size:11.0pt;line-height:107%;
font-family:&quot;Calibri&quot;,sans-serif;mso-ascii-theme-font:minor-latin;mso-fareast-font-family:
Calibri;mso-fareast-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:&quot;Times New Roman&quot;;mso-bidi-theme-font:minor-bidi;
mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA">Here&#8217;s an example of how you might register a module in code (note that it assumes your <strong>Shell</strong> project has a static reference to the module project):</span></p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C#</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>protected override void ConfigureModuleCatalog()
{
    var myModuleType = typeof(MyModule);
    Prism.Bootstrapper.ModuleCatalog.AddModule(
      new ModuleInfo()
      {
          ModuleName = myModuleType.Name,
          ModuleType = myModuleType.AssemblyQualifiedName,
          DependsOn = new Collection&lt;string>(new List&lt;string>()
          {
              "MyOtherModule",
              "MyServiceModule"
          })
      });
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #569CD6">protected</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">override</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">void</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">ConfigureModuleCatalog</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #569CD6">var</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">myModuleType</span><span style="color: #D4D4D4"> = </span><span style="color: #569CD6">typeof</span><span style="color: #D4D4D4">(</span><span style="color: #4EC9B0">MyModule</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #9CDCFE">Prism</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">Bootstrapper</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">ModuleCatalog</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">AddModule</span><span style="color: #D4D4D4">(</span></span>
<span class="line"><span style="color: #D4D4D4">      </span><span style="color: #569CD6">new</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">ModuleInfo</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">      {</span></span>
<span class="line"><span style="color: #D4D4D4">          </span><span style="color: #9CDCFE">ModuleName</span><span style="color: #D4D4D4"> = </span><span style="color: #9CDCFE">myModuleType</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">Name</span><span style="color: #D4D4D4">,</span></span>
<span class="line"><span style="color: #D4D4D4">          </span><span style="color: #9CDCFE">ModuleType</span><span style="color: #D4D4D4"> = </span><span style="color: #9CDCFE">myModuleType</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">AssemblyQualifiedName</span><span style="color: #D4D4D4">,</span></span>
<span class="line"><span style="color: #D4D4D4">          </span><span style="color: #9CDCFE">DependsOn</span><span style="color: #D4D4D4"> = </span><span style="color: #569CD6">new</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">Collection</span><span style="color: #D4D4D4">&lt;</span><span style="color: #569CD6">string</span><span style="color: #D4D4D4">&gt;(</span><span style="color: #569CD6">new</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">List</span><span style="color: #D4D4D4">&lt;</span><span style="color: #569CD6">string</span><span style="color: #D4D4D4">&gt;()</span></span>
<span class="line"><span style="color: #D4D4D4">          {</span></span>
<span class="line"><span style="color: #D4D4D4">              </span><span style="color: #CE9178">&quot;MyOtherModule&quot;</span><span style="color: #D4D4D4">,</span></span>
<span class="line"><span style="color: #D4D4D4">              </span><span style="color: #CE9178">&quot;MyServiceModule&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">          })</span></span>
<span class="line"><span style="color: #D4D4D4">      });</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<p class="wp-block-paragraph">In the above code, the <strong>DependsOn</strong> property can also be set in the attributes of the module class instead of here. The attributes are also where you set the name of the module referenced by <strong>myModuleType.Name</strong>.</p>



<h4 class="wp-block-heading" id="h-registering-modules-in-a-xaml-file"><span style="color:#1F4D78;">Registering Modules in a XAML File</span></h4>



<p class="wp-block-paragraph">Another option to declaratively define a module catalog is via a XAML file. Typically, you add the file as a resource to the <strong>Shell</strong> project. You then override the <strong>CreateModuleCatalog()</strong> method of your <strong>Bootstrapper </strong>and within that method call the <strong>CreateFromXaml()</strong> method of class <strong>Prism.Modularity.ModuleCatalog</strong>.</p>



<p class="wp-block-paragraph">The XAML might look something like this:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">XAML</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>&lt;!-- ModulesCatalog.xaml -->
&lt;Modularity:ModuleCatalog xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                          xmlns:sys="clr-namespace:System;assembly=mscorlib"
                          xmlns:Modularity="clr-namespace:Microsoft.Practices.Prism.Modularity;assembly=Microsoft.Practices.Prism">
    &lt;Modularity:ModuleInfoGroup InitializationMode="OnDemand">
        &lt;Modularity:ModuleInfo Ref="file://ModularityWithUnity.Desktop.MyOtherModule.dll" ModuleName="MyOtherModule" ModuleType="ModularityWithUnity.Desktop.MyOtherModule, ModularityWithUnity.Desktop.MyOtherModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
        &lt;Modularity:ModuleInfo Ref="file://ModularityWithUnity.Desktop.MyServiceModule.dll" ModuleName="MyServiceModule" ModuleType="ModularityWithUnity.Desktop.MyServiceModule, ModularityWithUnity.Desktop.MyServiceModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
        &lt;Modularity:ModuleInfo Ref="file://ModularityWithUnity.Desktop.MyModule.dll" ModuleName="MyModule" ModuleType="ModularityWithUnity.Desktop.MyModule, ModularityWithUnity.Desktop.MyModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
            &lt;Modularity:ModuleInfo.DependsOn>
                &lt;sys:String>MyOtherModule&lt;/sys:String>
                &lt;sys:String>MyServiceModule&lt;/sys:String>
            &lt;/Modularity:ModuleInfo.DependsOn>
        &lt;/Modularity:ModuleInfo>
    &lt;/Modularity:ModuleInfoGroup>
&lt;/Modularity:ModuleCatalog></textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #6A9955">&lt;!-- ModulesCatalog.xaml --&gt;</span></span>
<span class="line"><span style="color: #808080">&lt;</span><span style="color: #569CD6">Modularity:ModuleCatalog</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">xmlns</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">                          </span><span style="color: #9CDCFE">xmlns:x</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">                          </span><span style="color: #9CDCFE">xmlns:sys</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;clr-namespace:System;assembly=mscorlib&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">                          </span><span style="color: #9CDCFE">xmlns:Modularity</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;clr-namespace:Microsoft.Practices.Prism.Modularity;assembly=Microsoft.Practices.Prism&quot;</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Modularity:ModuleInfoGroup</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">InitializationMode</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;OnDemand&quot;</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Modularity:ModuleInfo</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Ref</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;file://ModularityWithUnity.Desktop.MyOtherModule.dll&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">ModuleName</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;MyOtherModule&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">ModuleType</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;ModularityWithUnity.Desktop.MyOtherModule, ModularityWithUnity.Desktop.MyOtherModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&quot;</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Modularity:ModuleInfo</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Ref</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;file://ModularityWithUnity.Desktop.MyServiceModule.dll&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">ModuleName</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;MyServiceModule&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">ModuleType</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;ModularityWithUnity.Desktop.MyServiceModule, ModularityWithUnity.Desktop.MyServiceModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&quot;</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Modularity:ModuleInfo</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Ref</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;file://ModularityWithUnity.Desktop.MyModule.dll&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">ModuleName</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;MyModule&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">ModuleType</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;ModularityWithUnity.Desktop.MyModule, ModularityWithUnity.Desktop.MyModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Modularity:ModuleInfo.DependsOn</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">sys:String</span><span style="color: #808080">&gt;</span><span style="color: #D4D4D4">MyOtherModule</span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">sys:String</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">sys:String</span><span style="color: #808080">&gt;</span><span style="color: #D4D4D4">MyServiceModule</span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">sys:String</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Modularity:ModuleInfo.DependsOn</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Modularity:ModuleInfo</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Modularity:ModuleInfoGroup</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Modularity:ModuleCatalog</span><span style="color: #808080">&gt;</span></span></code></pre></div>



<p class="wp-block-paragraph">Modules don&#8217;t have to be in a ModuleInfoGroup, but it allows for setting common properties for modules and is the only way to set module dependencies. In the Bootstrapper, you&#8217;d then have the following for ConfigureModuleCatalog():</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C#</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>protected override IModuleCatalog CreateModuleCatalog()
{
    return Prism.Modularity.ModuleCatalog.CreateFromXaml(new Uri("/PrismSample;component/ModulesCatalog.xaml", UriKind.Relative));
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #569CD6">protected</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">override</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">IModuleCatalog</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">CreateModuleCatalog</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">return</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Prism</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">Modularity</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">ModuleCatalog</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">CreateFromXaml</span><span style="color: #D4D4D4">(</span><span style="color: #569CD6">new</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">Uri</span><span style="color: #D4D4D4">(</span><span style="color: #CE9178">&quot;/PrismSample;component/ModulesCatalog.xaml&quot;</span><span style="color: #D4D4D4">, </span><span style="color: #9CDCFE">UriKind</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">Relative</span><span style="color: #D4D4D4">));</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<h4 class="wp-block-heading" id="h-registering-modules-in-a-configuration-file"><span style="color:#1F4D78;">Registering Modules in a Configuration File</span></h4>



<p class="wp-block-paragraph">Similar in idea to registering in a XAML file, this method has the added benefit of not requiring the application to be recompiled if you want to add and remove modules at runtime since the file is not compiled into the application. Setting attribute <strong><em>startupLoaded=&#8221;true&#8221;</em></strong> on a module will automatically load the module.</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">XML</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>&lt;?xml version="1.0" encoding="utf-8" ?>
&lt;configuration>
  &lt;configSections>
    &lt;section name="modules" type="Microsoft.Practices.Prism.Modularity.ModulesConfigurationSection, Microsoft.Practices.Prism"/>
  &lt;/configSections>
  &lt;modules>
    &lt;module assemblyFile="ModularityWithUnity.Desktop.MyOtherModule.dll" moduleType="ModularityWithUnity.Desktop.MyOtherModule, ModularityWithUnity.Desktop.MyOtherModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" moduleName="MyOtherModule" startupLoaded="false" />
    &lt;module assemblyFile="ModularityWithUnity.Desktop.MyServiceModule.dll" moduleType="ModularityWithUnity.Desktop.MyServiceModule, ModularityWithUnity.Desktop.MyServiceModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" moduleName="MyServiceModule" startupLoaded="false" />
    &lt;module assemblyFile="ModularityWithUnity.Desktop.MyModule.dll" moduleType="ModularityWithUnity.Desktop.MyModule, ModularityWithUnity.Desktop.MyModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" moduleName="MyModule" startupLoaded="false">
      &lt;dependencies>
        &lt;dependency moduleName="MyOtherModule"/>
        &lt;dependency moduleName="MyServiceModule"/>
      &lt;/dependencies>
    &lt;/module>
    &lt;module assemblyFile="ModularityWithUnity.Desktop.MyAutoLoadModule.dll" moduleType="ModularityWithUnity.Desktop.MyAutoLoadModule, ModularityWithUnity.Desktop.MyAutoLoadModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" moduleName="MyAutoLoadModule" startupLoaded="true" />
  &lt;/modules>
&lt;/configuration></textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #808080">&lt;?</span><span style="color: #569CD6">xml</span><span style="color: #9CDCFE"> version</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;1.0&quot;</span><span style="color: #9CDCFE"> encoding</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;utf-8&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">?&gt;</span></span>
<span class="line"><span style="color: #808080">&lt;</span><span style="color: #569CD6">configuration</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">configSections</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">section</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">name</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;modules&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">type</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;Microsoft.Practices.Prism.Modularity.ModulesConfigurationSection, Microsoft.Practices.Prism&quot;</span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">configSections</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">modules</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">module</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">assemblyFile</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;ModularityWithUnity.Desktop.MyOtherModule.dll&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">moduleType</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;ModularityWithUnity.Desktop.MyOtherModule, ModularityWithUnity.Desktop.MyOtherModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">moduleName</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;MyOtherModule&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">startupLoaded</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;false&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">module</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">assemblyFile</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;ModularityWithUnity.Desktop.MyServiceModule.dll&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">moduleType</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;ModularityWithUnity.Desktop.MyServiceModule, ModularityWithUnity.Desktop.MyServiceModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">moduleName</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;MyServiceModule&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">startupLoaded</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;false&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">module</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">assemblyFile</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;ModularityWithUnity.Desktop.MyModule.dll&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">moduleType</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;ModularityWithUnity.Desktop.MyModule, ModularityWithUnity.Desktop.MyModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">moduleName</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;MyModule&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">startupLoaded</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;false&quot;</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">      </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">dependencies</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">dependency</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">moduleName</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;MyOtherModule&quot;</span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">dependency</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">moduleName</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;MyServiceModule&quot;</span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">      </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">dependencies</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">module</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">module</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">assemblyFile</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;ModularityWithUnity.Desktop.MyAutoLoadModule.dll&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">moduleType</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;ModularityWithUnity.Desktop.MyAutoLoadModule, ModularityWithUnity.Desktop.MyAutoLoadModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">moduleName</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;MyAutoLoadModule&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">startupLoaded</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;true&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">modules</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #808080">&lt;/</span><span style="color: #569CD6">configuration</span><span style="color: #808080">&gt;</span></span></code></pre></div>



<p class="wp-block-paragraph">To specify that the configuration file is the source of your module catalog, you would add the following code to the <strong>Bootstrapper</strong>:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C#</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>protected override IModuleCatalog CreateModuleCatalog()
{
    return new ConfigurationModuleCatalog();
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #569CD6">protected</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">override</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">IModuleCatalog</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">CreateModuleCatalog</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">return</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">new</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">ConfigurationModuleCatalog</span><span style="color: #D4D4D4">();</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<h4 class="wp-block-heading" id="h-discovering-modules-in-a-local-directory-on-disk"><span style="color:#1F4D78;">Discovering Modules in a Local Directory on Disk</span></h4>



<p class="wp-block-paragraph">This is the method we will be using for this blog series. The module catalog scans the specified directory searching for assemblies defining each module in the application. This method requires the use of declarative attributes in the module classes to define the module names and any dependencies. (This is different from the other approaches where these attributes are defined as part of the catalog itself.) Aside from a mechanism to copy the module libraries to the catalog directory (typically accomplished by adding a post-build copy event to the module project), the only other thing needed is the following override in the <strong>Bootstrapper</strong>:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C#</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>protected override IModuleCatalog CreateModuleCatalog()
{
    // Use local directory as module catalog
    return new DirectoryModuleCatalog { ModulePath = "Modules" };
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #569CD6">protected</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">override</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">IModuleCatalog</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">CreateModuleCatalog</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #6A9955">    // Use local directory as module catalog</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">return</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">new</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">DirectoryModuleCatalog</span><span style="color: #D4D4D4"> { </span><span style="color: #9CDCFE">ModulePath</span><span style="color: #D4D4D4"> = </span><span style="color: #CE9178">&quot;Modules&quot;</span><span style="color: #D4D4D4"> };</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<p class="wp-block-paragraph">If we were using <strong>MEF</strong> instead of <strong>Unity</strong>, we wouldn&#8217;t override <strong>CreateModuleCatalog()</strong>. Instead we&#8217;d create a new instance of the <strong>DirectoryCatalog </strong>class and add that to the <strong>MEF AggregateCatalog</strong> as follows:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C#</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>/// &lt;summary>
/// Imperatively add type registrations to MEF's Aggregate Catalog
/// &lt;/summary>
protected override void ConfigureAggregateCatalog()
{
    base.ConfigureAggregateCatalog();

    // Add Shell assembly
    this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Bootstrapper).Assembly));

    // Add module catalog
    var moduleCatalog = new DirectoryCatalog("Modules");
    this.AggregateCatalog.Catalogs.Add(moduleCatalog);
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #6A9955">/// </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #6A9955">/// Imperatively add type registrations to MEF&apos;s Aggregate Catalog</span></span>
<span class="line"><span style="color: #6A9955">/// </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #569CD6">protected</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">override</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">void</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">ConfigureAggregateCatalog</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #569CD6">base</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">ConfigureAggregateCatalog</span><span style="color: #D4D4D4">();</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A9955">    // Add Shell assembly</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #569CD6">this</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">AggregateCatalog</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">Catalogs</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">Add</span><span style="color: #D4D4D4">(</span><span style="color: #569CD6">new</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">AssemblyCatalog</span><span style="color: #D4D4D4">(</span><span style="color: #569CD6">typeof</span><span style="color: #D4D4D4">(</span><span style="color: #4EC9B0">Bootstrapper</span><span style="color: #D4D4D4">).</span><span style="color: #9CDCFE">Assembly</span><span style="color: #D4D4D4">));</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A9955">    // Add module catalog</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #569CD6">var</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">moduleCatalog</span><span style="color: #D4D4D4"> = </span><span style="color: #569CD6">new</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">DirectoryCatalog</span><span style="color: #D4D4D4">(</span><span style="color: #CE9178">&quot;Modules&quot;</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #569CD6">this</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">AggregateCatalog</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">Catalogs</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">Add</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">moduleCatalog</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<h2 class="wp-block-heading" id="h-create-the-modules"><span style="color:#1F4D78;">Create the Modules</span></h2>



<p class="wp-block-paragraph">We&#8217;ve defined our module catalog, so it&#8217;s time to create the modules. We start by adding a folder to our solution tree called <strong>Modules</strong>. (This step isn&#8217;t strictly necessary, but I find it nice for organization of the assemblies. Your mileage may vary.) Right-click on the <strong>Modules </strong>folder and select <strong>Add→New Project&#8230;</strong>. Name the class library <strong>NavigationMenu</strong> and click <strong>OK</strong>.</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/PrismNavigationMenuProject_1.png" alt="Prism Module Library for Navigation Menu" title="New Navigation Menu Module Project"/></figure>



<p class="wp-block-paragraph">Delete the <strong>Class1.cs</strong> file that is created. Next we add the <strong>Prism </strong>and <strong>Unity</strong> libraries to our module. This process is identical to what we did with the <strong>Shell </strong>project. Right click on the <strong>NavigationMenu </strong>project and select <strong>Manage NuGet Packages&#8230;</strong>. Click on the <strong>Browse</strong> tab and type <strong>prism.unity</strong> in the search box. Select the <strong>Prism.Unity</strong> package and install it.</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Prism-Sample-Navigation-Menu-NuGet.png" alt="Adding Prism and Unity Libraries via NuGet" title="Adding Prism and Unity Libraries via NuGet"/></figure>



<p class="wp-block-paragraph">Now is as good of a time as any to also add a reference to our <strong>Infrastructure </strong>assembly. We will define all our module names as constants in a static class as part of <strong>Infrastructure</strong>. After adding a reference to the <strong>Infrastructure </strong>project in our module, right click on the <strong>Constants</strong> folder in the project and select <strong>Add→New From Template→Class</strong>. In the popup box type <strong>ModuleNames</strong> and click <strong>OK</strong>. Add a constant for the Navigation Menu module name to this class as follows:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C#</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>namespace Infrastructure.Constants
{
    public static class ModuleNames
    {
        public const string NAVIGATION_MENU = "NavigationMenu";
    }
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #569CD6">namespace</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">Infrastructure</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Constants</span></span>
<span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">static</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">class</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">ModuleNames</span></span>
<span class="line"><span style="color: #D4D4D4">    {</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">const</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">string</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">NAVIGATION_MENU</span><span style="color: #D4D4D4"> = </span><span style="color: #CE9178">&quot;NavigationMenu&quot;</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">    }</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<p class="wp-block-paragraph">The next step to is to create the module initialization file, which defines the module attributes and registers the interfaces and classes the module implements. Right click on the <strong>NavigationMenuModule </strong>project and select <strong>Add→New From Template→Class</strong>. In the popup box type <strong>NavigationMenuModule</strong> and click <strong>OK</strong>. This new class needs to implement the <strong>IModule</strong> interface, which consists of one method called <strong>Initialize()</strong>. The class also needs a declarative <strong>ModuleAttribute </strong>applied that defines at least the <strong>ModuleName </strong>property. In this case we set the property to the constant we defined above as follows:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C#</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>using Infrastructure.Constants;
using Prism.Modularity;

namespace NavigationMenu
{
    /// &lt;summary>
    /// Register components of module with Unity/Prism
    /// &lt;/summary>
    &#91;Module(ModuleName = ModuleNames.NAVIGATION_MENU)&#93;
    public class NavigationMenuModule : IModule
    {
        public void Initialize()
        {
        }
    }
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">Infrastructure</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Constants</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">Prism</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Modularity</span><span style="color: #D4D4D4">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #569CD6">namespace</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">NavigationMenu</span></span>
<span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #6A9955">    /// </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #6A9955">    /// Register components of module with Unity/Prism</span></span>
<span class="line"><span style="color: #6A9955">    /// </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    &#91;</span><span style="color: #4EC9B0">Module</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">ModuleName</span><span style="color: #D4D4D4"> = </span><span style="color: #9CDCFE">ModuleNames</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">NAVIGATION_MENU</span><span style="color: #D4D4D4">)&#93;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">class</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">NavigationMenuModule</span><span style="color: #D4D4D4"> : </span><span style="color: #4EC9B0">IModule</span></span>
<span class="line"><span style="color: #D4D4D4">    {</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">void</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">Initialize</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">        {</span></span>
<span class="line"><span style="color: #D4D4D4">        }</span></span>
<span class="line"><span style="color: #D4D4D4">    }</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<p class="wp-block-paragraph">We still have to copy the module library to our catalog folder. To this we open the properties of our <strong>NavigationMenu </strong>project and add the following post-build event:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">BAT (Batchfile)</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>robocopy "$(TargetDir)\" "$(SolutionDir)PrismSample\$(OutDir)Modules" NavigationMenu.dll
if %errorlevel% geq 8 exit 1
exit 0</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #569CD6">robocopy</span><span style="color: #D4D4D4"> </span><span style="color: #CE9178">&quot;$(TargetDir)\&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #CE9178">&quot;$(SolutionDir)PrismSample\$(OutDir)Modules&quot;</span><span style="color: #D4D4D4"> NavigationMenu.dll</span></span>
<span class="line"><span style="color: #C586C0">if</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">%errorlevel%</span><span style="color: #D4D4D4"> geq </span><span style="color: #B5CEA8">8</span><span style="color: #D4D4D4"> </span><span style="color: #C586C0">exit</span><span style="color: #D4D4D4"> </span><span style="color: #B5CEA8">1</span></span>
<span class="line"><span style="color: #C586C0">exit</span><span style="color: #D4D4D4"> </span><span style="color: #B5CEA8">0</span></span></code></pre></div>



<p class="wp-block-paragraph">(Note:&nbsp; Instead of <strong>robocopy </strong>(i.e. Robust Copy) some people might use <strong>xcopy </strong>here. The problem with <strong>xcopy </strong>is that Microsoft officially deprecated it a while ago. Additionally, <strong>robocopy </strong>has nicer error handling. I have found, however, that sometimes <strong>robocopy </strong>seems to hang for a while when building the application in Visual Studio, particularly when many modules are built. I&#8217;ve yet to figure out why, but it might be that <strong>robocopy </strong>is slow to release the directory after it finishes copying, so when the next module tries to copy to the directory it can&#8217;t get access. Occasionally, <strong>robocopy </strong>will even time out and the build will fail. Building again usually cleans up the issue.)</p>



<p class="wp-block-paragraph">The final step to getting our module to load is to ensure the solution builds this module before it builds the shell. Right-click on the <strong>PrismSample </strong>solution in Solution Explorer and select <strong>Project Dependencies&#8230;</strong>. Select the <strong>PrismSample </strong>project under the <strong>Projects:</strong> drop-down and you should see that <strong>Infrastructure </strong>is already checked. Check <strong>NavigationMenu </strong>as well. If you look at the Build Order tab you should see <strong>Infrastructure </strong>listed first in the order and <strong>Prism Sample</strong> listed last.</p>



<p class="wp-block-paragraph">Following a similar process to above that we used with <strong>NavigationMenu</strong>, we can add the <strong>TopRegion</strong>, <strong>MiddleRegion</strong>, and <strong>BottomRegion </strong>modules as well. (As mentioned in the previous part of this series in regards to the shell regions, a real application would have more descriptive names for what the other three modules actually do.) Our application will run, but since we haven&#8217;t implemented any actual functionality in our modules, it does nothing other than display a logo at this point. For the final section of this part of the series, I&#8217;ll create a simple menu view and show how to register it with a region for display.</p>



<h2 class="wp-block-heading" id="h-view-composition-discovery"><span style="color:#1F4D78;">View Composition (Discovery)</span></h2>



<p class="wp-block-paragraph">View composition is the construction of a view. There are two ways to create and display a view in a region:</p>



<ul class="wp-block-list">
<li>Automatically through discovery</li>



<li>Programmatically through injection</li>
</ul>



<p class="wp-block-paragraph">Discovery sets up a relationship in the <strong>RegionViewRegistry </strong>between a region&#8217;s name and a type of view. When a region is created, all view types associated with the region are automatically instantiated and their corresponding views loaded. With this method there is no explicit control over when views are loaded and displayed.</p>



<p class="wp-block-paragraph">Injection involves obtaining a reference to a region and then programmatically injecting views into it. This gives you full control over when views are loaded, removed, and displayed. However, you cannot add a view to a region that has not been created yet.</p>



<p class="wp-block-paragraph">For this part of the blog series, we concern ourselves only with discovery. We&#8217;ll come back to injection in a later part of this series when we introduce the <strong>View Navigation AP</strong>I.</p>



<p class="wp-block-paragraph">We start by creating the view for our menu by adding a new WPF User Control to our <strong>NavigationMenu </strong>project:</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Prism-Sample-Navigation-Menu-View.png" alt="Adding WPF User Control for Navigation Menu View" title="Adding WPF User Control for Navigation Menu View"/></figure>



<p class="wp-block-paragraph">(Note: After creating the user control, we&#8217;ll likely need to add a reference to <strong>System.Xaml</strong> to our project.)</p>



<p class="wp-block-paragraph">At this point it makes sense to create a Resource Dictionary to hold the control styles common to the various views in our application. We&#8217;ll add a <strong>SharedResources</strong> folder to the <strong>Infrastructure </strong>project and to that folder we add a new resource dictionary. Since our <strong>Infrastructure </strong>project is a Class Library, however,&nbsp;we can&#8217;t add the file through the convenience of the <strong>Add New Item</strong> dialog, so we&#8217;ll have to do it manually. (Or if you use <strong>Resharper</strong> like I do, you can select the &#8220;<strong>More&#8230;</strong>&#8221; menu from the <strong>Add New From Template</strong> menu and it will give you the option to add one there.) We&#8217;ll name the resource dictionary <strong>ResourceDictionary.xaml</strong>, and once we add it, we&#8217;ll also add a reference to the .NET <strong>PresentationFramework</strong> library to our <strong>Infrastructure </strong>project so that the resource dictionary is supported. For now our resource dictionary is pretty straightforward and looks like this:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">XAML</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:system="clr-namespace:System;assembly=mscorlib">

    &lt;!--Fonts-->
    &lt;system:Double x:Key="NormalFontSize">26&lt;/system:Double>
    &lt;FontFamily x:Key="NormalFont">Century Gothic&lt;/FontFamily>

    &lt;!--Colors-->
    &lt;Color x:Key="NormalFontColor">#FF5F5F5F&lt;/Color>

    &lt;!--Brushes-->
    &lt;SolidColorBrush x:Key="NormalForegroundBrush" Color="{StaticResource NormalFontColor}" />

    &lt;!--TextBlocks-->
    &lt;Style x:Key="NormalTextBlockStyle" TargetType="TextBlock">
        &lt;Setter Property="FontFamily" Value="{StaticResource NormalFont}" />
        &lt;Setter Property="Foreground" Value="{StaticResource NormalForegroundBrush}" />
        &lt;Setter Property="FontSize" Value="{StaticResource NormalFontSize}" />
    &lt;/Style>

    &lt;!--Controls-->
    &lt;Style x:Key="BaseControlStyle" TargetType="Control">
        &lt;Setter Property="FontFamily" Value="{StaticResource NormalFont}" />
        &lt;Setter Property="Foreground" Value="{StaticResource NormalForegroundBrush}" />
        &lt;Setter Property="FontSize" Value="{StaticResource NormalFontSize}" />
    &lt;/Style>
    
&lt;/ResourceDictionary></textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #808080">&lt;</span><span style="color: #569CD6">ResourceDictionary</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">xmlns</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">                    </span><span style="color: #9CDCFE">xmlns:x</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">                    </span><span style="color: #9CDCFE">xmlns:system</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;clr-namespace:System;assembly=mscorlib&quot;</span><span style="color: #808080">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #6A9955">&lt;!--Fonts--&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">system:Double</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">x:Key</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;NormalFontSize&quot;</span><span style="color: #808080">&gt;</span><span style="color: #D4D4D4">26</span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">system:Double</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">FontFamily</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">x:Key</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;NormalFont&quot;</span><span style="color: #808080">&gt;</span><span style="color: #D4D4D4">Century Gothic</span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">FontFamily</span><span style="color: #808080">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #6A9955">&lt;!--Colors--&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Color</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">x:Key</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;NormalFontColor&quot;</span><span style="color: #808080">&gt;</span><span style="color: #D4D4D4">#FF5F5F5F</span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Color</span><span style="color: #808080">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #6A9955">&lt;!--Brushes--&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">SolidColorBrush</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">x:Key</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;NormalForegroundBrush&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Color</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;{StaticResource NormalFontColor}&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #6A9955">&lt;!--TextBlocks--&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Style</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">x:Key</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;NormalTextBlockStyle&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">TargetType</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;TextBlock&quot;</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Setter</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Property</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;FontFamily&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;{StaticResource NormalFont}&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Setter</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Property</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;Foreground&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;{StaticResource NormalForegroundBrush}&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Setter</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Property</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;FontSize&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;{StaticResource NormalFontSize}&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Style</span><span style="color: #808080">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #6A9955">&lt;!--Controls--&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Style</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">x:Key</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;BaseControlStyle&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">TargetType</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;Control&quot;</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Setter</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Property</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;FontFamily&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;{StaticResource NormalFont}&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Setter</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Property</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;Foreground&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;{StaticResource NormalForegroundBrush}&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Setter</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Property</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;FontSize&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;{StaticResource NormalFontSize}&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Style</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span></span>
<span class="line"><span style="color: #808080">&lt;/</span><span style="color: #569CD6">ResourceDictionary</span><span style="color: #808080">&gt;</span></span></code></pre></div>



<p class="wp-block-paragraph">In order for this to build, we&#8217;ll need to add references to the <strong>PresentationCore</strong>, <strong>WindowsBase </strong>and <strong>System.Xaml</strong> libraries to our <strong>Infrastructure </strong>project.</p>



<p class="wp-block-paragraph">And while we&#8217;re add it, this would be a good point to add localizable strings to that project as well (though, this application will never need to worry about it). We&#8217;ll add a new folder called <strong>Strings</strong> as a subfolder to our <strong>SharedResources </strong>folder and to that new folder add a new <strong>Resources File</strong> with a <strong>Public </strong>access modifier we&#8217;ll call <strong>Text.resx</strong>.</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Prism-Sample-Text-Resource.png" alt="Adding a New Text Resource File" title="Adding a New Text Resource File"/></figure>



<p class="wp-block-paragraph">Going back to our <strong>NavigationMenu.xaml</strong> file, we will implement a fairly simple menu as follows:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">XAML</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>&lt;UserControl x:Class="NavigationMenu.NavigationMenu"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:str="clr-namespace:Infrastructure.SharedResources.Strings;assembly=Infrastructure"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d"
             d:DesignHeight="800" d:DesignWidth="300">

    &lt;UserControl.Resources>
        &lt;ResourceDictionary>
            &lt;ResourceDictionary.MergedDictionaries>
                &lt;ResourceDictionary Source="/Infrastructure;component/SharedResources/ResourceDictionary.xaml" />
            &lt;/ResourceDictionary.MergedDictionaries>
        &lt;/ResourceDictionary>
    &lt;/UserControl.Resources>

    &lt;Grid>
        &lt;StackPanel Background="White">

            &lt;StackPanel.Resources>
                &lt;Style TargetType="Button" BasedOn="{StaticResource BaseControlStyle}">
                    &lt;Setter Property="Background" Value="Transparent" />
                    &lt;Setter Property="Template">
                        &lt;Setter.Value>
                            &lt;ControlTemplate TargetType="Button">
                                &lt;Border Padding="10" Background="{TemplateBinding Background}">
                                    &lt;ContentPresenter VerticalAlignment="Center" />
                                &lt;/Border>
                            &lt;/ControlTemplate>
                        &lt;/Setter.Value>
                    &lt;/Setter>
                    &lt;Style.Triggers>
                        &lt;Trigger Property="IsMouseOver" Value="True">
                            &lt;Setter Property="Foreground" Value="#2D82B9" />
                        &lt;/Trigger>
                        &lt;Trigger Property="IsPressed" Value="True">
                            &lt;Setter Property="Foreground" Value="{StaticResource NormalForegroundBrush}" />
                            &lt;Setter Property="Background" Value="LightGray" />
                        &lt;/Trigger>
                    &lt;/Style.Triggers>
                &lt;/Style>
            &lt;/StackPanel.Resources>

            &lt;Button Content="{x:Static str:Text.About}" />
            &lt;Button Content="{x:Static str:Text.CreateError}" />
            &lt;Button Content="{x:Static str:Text.Exit}" />
        &lt;/StackPanel>
    &lt;/Grid>
&lt;/UserControl></textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #808080">&lt;</span><span style="color: #569CD6">UserControl</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">x:Class</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;NavigationMenu.NavigationMenu&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">             </span><span style="color: #9CDCFE">xmlns</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">             </span><span style="color: #9CDCFE">xmlns:x</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">             </span><span style="color: #9CDCFE">xmlns:mc</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">             </span><span style="color: #9CDCFE">xmlns:str</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;clr-namespace:Infrastructure.SharedResources.Strings;assembly=Infrastructure&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">             </span><span style="color: #9CDCFE">xmlns:d</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;http://schemas.microsoft.com/expression/blend/2008&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">             </span><span style="color: #9CDCFE">mc:Ignorable</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;d&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">             </span><span style="color: #9CDCFE">d:DesignHeight</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;800&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">d:DesignWidth</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;300&quot;</span><span style="color: #808080">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">UserControl.Resources</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">ResourceDictionary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">ResourceDictionary.MergedDictionaries</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">ResourceDictionary</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Source</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;/Infrastructure;component/SharedResources/ResourceDictionary.xaml&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">ResourceDictionary.MergedDictionaries</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">ResourceDictionary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">UserControl.Resources</span><span style="color: #808080">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Grid</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">StackPanel</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Background</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;White&quot;</span><span style="color: #808080">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">StackPanel.Resources</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Style</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">TargetType</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;Button&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">BasedOn</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;{StaticResource BaseControlStyle}&quot;</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Setter</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Property</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;Background&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;Transparent&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Setter</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Property</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;Template&quot;</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                        </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Setter.Value</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                            </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">ControlTemplate</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">TargetType</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;Button&quot;</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                                </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Border</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Padding</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;10&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Background</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;{TemplateBinding Background}&quot;</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                                    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">ContentPresenter</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">VerticalAlignment</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;Center&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                                </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Border</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                            </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">ControlTemplate</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                        </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Setter.Value</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                    </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Setter</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Style.Triggers</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                        </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Trigger</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Property</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;IsMouseOver&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;True&quot;</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                            </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Setter</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Property</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;Foreground&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;#2D82B9&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                        </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Trigger</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                        </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Trigger</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Property</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;IsPressed&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;True&quot;</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                            </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Setter</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Property</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;Foreground&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;{StaticResource NormalForegroundBrush}&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                            </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Setter</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Property</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;Background&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;LightGray&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                        </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Trigger</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                    </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Style.Triggers</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Style</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">StackPanel.Resources</span><span style="color: #808080">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Button</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Content</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;{x:Static str:Text.About}&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Button</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Content</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;{x:Static str:Text.CreateError}&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Button</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Content</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;{x:Static str:Text.Exit}&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">StackPanel</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Grid</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #808080">&lt;/</span><span style="color: #569CD6">UserControl</span><span style="color: #808080">&gt;</span></span></code></pre></div>



<p class="wp-block-paragraph">Finally, in <strong>NavigationMenuModule.cs</strong> we will register our module via the <strong>Module </strong>declarative attribute and then in the <strong>Initialize()</strong> method of the <strong>IModule </strong>interface we register this view with the region we&#8217;ve defined for it:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C#</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>using Infrastructure.Constants;
using Prism.Modularity;
using Prism.Regions;

namespace NavigationMenu
{
    /// &lt;summary>
    /// Register components of module with Unity/Prism
    /// &lt;/summary>
    &#91;Module(ModuleName = ModuleNames.NAVIGATION_MENU)&#93;
    public class NavigationMenuModule : IModule
    {
        private readonly IRegionManager _regionManager;

        public NavigationMenuModule(IRegionManager regionManager)
        {
            this._regionManager = regionManager;
        }

        public void Initialize()
        {
            this._regionManager.RegisterViewWithRegion(RegionNames.MENU_REGION, typeof(NavigationMenu));
        }
    }
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">Infrastructure</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Constants</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">Prism</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Modularity</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">Prism</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Regions</span><span style="color: #D4D4D4">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #569CD6">namespace</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">NavigationMenu</span></span>
<span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #6A9955">    /// </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #6A9955">    /// Register components of module with Unity/Prism</span></span>
<span class="line"><span style="color: #6A9955">    /// </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    &#91;</span><span style="color: #4EC9B0">Module</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">ModuleName</span><span style="color: #D4D4D4"> = </span><span style="color: #9CDCFE">ModuleNames</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">NAVIGATION_MENU</span><span style="color: #D4D4D4">)&#93;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">class</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">NavigationMenuModule</span><span style="color: #D4D4D4"> : </span><span style="color: #4EC9B0">IModule</span></span>
<span class="line"><span style="color: #D4D4D4">    {</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">private</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">readonly</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">IRegionManager</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">_regionManager</span><span style="color: #D4D4D4">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">NavigationMenuModule</span><span style="color: #D4D4D4">(</span><span style="color: #4EC9B0">IRegionManager</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">regionManager</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">        {</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #569CD6">this</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">_regionManager</span><span style="color: #D4D4D4"> = </span><span style="color: #9CDCFE">regionManager</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">        }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">void</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">Initialize</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">        {</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #569CD6">this</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">_regionManager</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">RegisterViewWithRegion</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">RegionNames</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">MENU_REGION</span><span style="color: #D4D4D4">, </span><span style="color: #569CD6">typeof</span><span style="color: #D4D4D4">(</span><span style="color: #4EC9B0">NavigationMenu</span><span style="color: #D4D4D4">));</span></span>
<span class="line"><span style="color: #D4D4D4">        }</span></span>
<span class="line"><span style="color: #D4D4D4">    }</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<p class="wp-block-paragraph">For <strong>MEF</strong>, registration is a bit different. We first need to add the <strong>[Export] </strong>attribute to our <strong>NavigationMenu.xaml.cs</strong> file as follows:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C#</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>using System.ComponentModel.Composition;
using System.Windows.Controls;

namespace NavigationMenu
{
    /// &lt;summary>
    /// Interaction logic for NavigationMenu.xaml
    /// &lt;/summary>
    &#91;Export&#93;
    public partial class NavigationMenu : UserControl
    {
        public NavigationMenu()
        {
            this.InitializeComponent();
        }
    }
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">System</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">ComponentModel</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Composition</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">System</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Windows</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Controls</span><span style="color: #D4D4D4">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #569CD6">namespace</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">NavigationMenu</span></span>
<span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #6A9955">    /// </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #6A9955">    /// Interaction logic for NavigationMenu.xaml</span></span>
<span class="line"><span style="color: #6A9955">    /// </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    &#91;</span><span style="color: #4EC9B0">Export</span><span style="color: #D4D4D4">&#93;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">partial</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">class</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">NavigationMenu</span><span style="color: #D4D4D4"> : </span><span style="color: #4EC9B0">UserControl</span></span>
<span class="line"><span style="color: #D4D4D4">    {</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">NavigationMenu</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">        {</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #569CD6">this</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">InitializeComponent</span><span style="color: #D4D4D4">();</span></span>
<span class="line"><span style="color: #D4D4D4">        }</span></span>
<span class="line"><span style="color: #D4D4D4">    }</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<p class="wp-block-paragraph">And then in our module file we register the module using the <strong>Module </strong>attribute as we did in <strong>Unity</strong>, but we also have to add a <strong>ModuleExport </strong>attribute for the module itself, and declare the constructor as an <strong>ImportingConstructor </strong>so that the region manager can be set through dependency injection:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C#</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>using System.ComponentModel.Composition;
using Infrastructure.Constants;
using Prism.Mef.Modularity;
using Prism.Modularity;
using Prism.Regions;

namespace NavigationMenu
{
    /// &lt;summary>
    /// Register components of module with MEF/Prism
    /// &lt;/summary>
    &#91;Module(ModuleName = ModuleNames.NAVIGATION_MENU)&#93;
    &#91;ModuleExport(typeof(NavigationMenuModule), InitializationMode = InitializationMode.WhenAvailable)&#93;
    public class NavigationMenuModule : IModule
    {
        private readonly IRegionManager _regionManager;

        &#91;ImportingConstructor&#93;
        public NavigationMenuModule(IRegionManager regionManager)
        {
            this._regionManager = regionManager;
        }

        public void Initialize()
        {
            this._regionManager.RegisterViewWithRegion(RegionNames.MENU_REGION, typeof(NavigationMenu));
        }
    }
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">System</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">ComponentModel</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Composition</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">Infrastructure</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Constants</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">Prism</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Mef</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Modularity</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">Prism</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Modularity</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">Prism</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Regions</span><span style="color: #D4D4D4">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #569CD6">namespace</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">NavigationMenu</span></span>
<span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #6A9955">    /// </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #6A9955">    /// Register components of module with MEF/Prism</span></span>
<span class="line"><span style="color: #6A9955">    /// </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    &#91;</span><span style="color: #4EC9B0">Module</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">ModuleName</span><span style="color: #D4D4D4"> = </span><span style="color: #9CDCFE">ModuleNames</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">NAVIGATION_MENU</span><span style="color: #D4D4D4">)&#93;</span></span>
<span class="line"><span style="color: #D4D4D4">    &#91;</span><span style="color: #4EC9B0">ModuleExport</span><span style="color: #D4D4D4">(</span><span style="color: #569CD6">typeof</span><span style="color: #D4D4D4">(</span><span style="color: #4EC9B0">NavigationMenuModule</span><span style="color: #D4D4D4">), </span><span style="color: #9CDCFE">InitializationMode</span><span style="color: #D4D4D4"> = </span><span style="color: #9CDCFE">InitializationMode</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">WhenAvailable</span><span style="color: #D4D4D4">)&#93;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">class</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">NavigationMenuModule</span><span style="color: #D4D4D4"> : </span><span style="color: #4EC9B0">IModule</span></span>
<span class="line"><span style="color: #D4D4D4">    {</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">private</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">readonly</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">IRegionManager</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">_regionManager</span><span style="color: #D4D4D4">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">        &#91;</span><span style="color: #4EC9B0">ImportingConstructor</span><span style="color: #D4D4D4">&#93;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">NavigationMenuModule</span><span style="color: #D4D4D4">(</span><span style="color: #4EC9B0">IRegionManager</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">regionManager</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">        {</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #569CD6">this</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">_regionManager</span><span style="color: #D4D4D4"> = </span><span style="color: #9CDCFE">regionManager</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">        }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">void</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">Initialize</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">        {</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #569CD6">this</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">_regionManager</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">RegisterViewWithRegion</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">RegionNames</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">MENU_REGION</span><span style="color: #D4D4D4">, </span><span style="color: #569CD6">typeof</span><span style="color: #D4D4D4">(</span><span style="color: #4EC9B0">NavigationMenu</span><span style="color: #D4D4D4">));</span></span>
<span class="line"><span style="color: #D4D4D4">        }</span></span>
<span class="line"><span style="color: #D4D4D4">    }</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<p class="wp-block-paragraph">If we build the application, we now see our menu has populated the region on the left-hand side. (The other three modules have also been added with place-holder views.) Of course, it doesn&#8217;t do anything at this point, but we will shortly rectify that in <a href="https://static.dmcinfo.com/latest-thinking/blog">Part 4:&nbsp; Intermodule Communication (coming soon)</a>.</p>



<p class="wp-block-paragraph">&nbsp;</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Prism-Unity-WPF-Application-Shell-Part-3.png" alt="WPF Prism Application Shell Window (Unity)"/></figure>



<p class="wp-block-paragraph">The Unity-based solution files and source code for this part can be downloaded by clicking below</p>



<div class="wp-block-file"><a id="wp-block-file--media-c2fe66ee-944a-4b3d-bac3-8e5d6b5898dc" href="https://static.dmcinfo.com/wp-content/uploads/2025/06/PrismSampleUnity-Part-3.zip">PrismSampleUnity &#8212; Part 3</a><a href="https://static.dmcinfo.com/wp-content/uploads/2025/06/PrismSampleUnity-Part-3.zip" class="wp-block-file__button wp-element-button" download aria-describedby="wp-block-file--media-c2fe66ee-944a-4b3d-bac3-8e5d6b5898dc">Download</a></div>



<p class="wp-block-paragraph">The MEF-based solution files and source code for this part can be downloaded by clicking below</p>



<div class="wp-block-file"><a id="wp-block-file--media-09879d29-3086-46fc-904d-3bc25ae1ce01" href="https://static.dmcinfo.com/wp-content/uploads/2025/06/PrismSampleMef-Part-3.zip">PrismSampleMef &#8212; Part 3</a><a href="https://static.dmcinfo.com/wp-content/uploads/2025/06/PrismSampleMef-Part-3.zip" class="wp-block-file__button wp-element-button" download aria-describedby="wp-block-file--media-09879d29-3086-46fc-904d-3bc25ae1ce01">Download</a></div>



<h2 class="wp-block-heading" id="h-a-properly-pleasing-prism-primer-the-parts">A Properly Pleasing Prism Primer &#8211; The Parts:</h2>



<p class="wp-block-paragraph"><a href="https://static.dmcinfo.com/latest-thinking/blog/id/9282/a-properly-pleasing-prism-primer--part-1-an-introduction">Part 1:&nbsp; An Introduction</a><br>
<a href="https://static.dmcinfo.com/latest-thinking/blog/id/9295/a-properly-pleasing-prism-primer--part-2-the-shell">Part 2:&nbsp; The Shell and Bootstrapper</a><br>
<a href="https://static.dmcinfo.com/latest-thinking/blog/id/9298/a-properly-pleasing-prism-primer--part-3-modules">Part 3:&nbsp; Modules</a><br>
<a href="https://static.dmcinfo.com/latest-thinking/blog">Part 4:&nbsp; Intermodule Communication (Coming soon)</a></p>



<p class="wp-block-paragraph"><a href="https://static.dmcinfo.com/latest-thinking/blog/articletype/categoryview/categoryid/136/c-net-application-development">Learn more about DMC&#8217;s .NET application development services.</a></p>
<p>The post <a href="https://static.dmcinfo.com/blog/25145/a-properly-pleasing-primer-tutorial-for-wpf-prism-part-3-modules/">A Properly Pleasing Primer Tutorial for WPF Prism &#8211; Part 3:  Modules</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>A Properly Pleasing Primer Tutorial for WPF Prism &#8211; Part 2:  The Shell and Bootstrapper</title>
		<link>https://static.dmcinfo.com/blog/25160/a-properly-pleasing-primer-tutorial-for-wpf-prism-part-2-the-shell-and-bootstrapper/</link>
		
		<dc:creator><![CDATA[DMC]]></dc:creator>
		<pubDate>Wed, 28 Sep 2016 16:23:53 +0000</pubDate>
				<category><![CDATA[PC Application Development]]></category>
		<category><![CDATA[C# .NET Application Development]]></category>
		<category><![CDATA[MS Visual Studio/.NET]]></category>
		<guid isPermaLink="false">https://static.dmcinfo.com/blog/25160/a-properly-pleasing-primer-tutorial-for-wpf-prism-part-2-the-shell-and-bootstrapper/</guid>

					<description><![CDATA[<p>In Part 1 of this series, I gave a quick summary of what Prism is, and when and why you would want to use it. The remaining parts of this series will address&#160;the &#8220;how&#8221; of using it. Since this series is largely an overview,&#160;I won&#8217;t cover everything you can possibly do under Prism. And since [&#8230;]</p>
<p>The post <a href="https://static.dmcinfo.com/blog/25160/a-properly-pleasing-primer-tutorial-for-wpf-prism-part-2-the-shell-and-bootstrapper/">A Properly Pleasing Primer Tutorial for WPF Prism &#8211; Part 2:  The Shell and Bootstrapper</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">In <a href="/latest-thinking/blog/id/9282/a-properly-pleasing-prism-primer--part-1-an-introduction">Part 1</a> of this series, I gave a quick summary of what Prism is, and when and why you would want to use it. The remaining parts of this series will address&nbsp;the &#8220;how&#8221; of using it. Since this series is largely an overview,&nbsp;I won&#8217;t cover everything you can possibly do under Prism. And since Prism is designed so that the programmer can pick and choose what functionality they need, not everything I cover here will be relevant to all applications. However, the goal is that this series will be a good jumping-off point for your own Prism application development. Part 2 will cover two components you&#8217;ll find in every Prism application:&nbsp; the Shell and the Bootstrapper.</p>



<h2 class="wp-block-heading" id="h-the-shell">The Shell</h2>



<p class="wp-block-paragraph">Composite applications are architected such that individual parts of the application can be developed, tested, and modified independent from other parts. If you think of the application as a painting, the shell is the canvas, a container that integrates everything together in a coherent whole. It is essentially the “application” part of the composite application. The XAML file in the shell consists of one or more regions, which are named logical placeholders into which views are injected. &nbsp;Each region is attached to a common container control such as a ContentControl, ItemsControl, ListBox, or TabControl. The shell we’ll be using for this sample application will consist of four regions each attached to a ContentControl.</p>



<p class="wp-block-paragraph">Start by opening Visual Studio and selecting the New Project dialog from the file menu. Create a WPF Application.</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Shell.png" alt="New Prism WPF Application Solution" title="New Prism WPF Application Solution"/></figure>



<p class="wp-block-paragraph">Click OK to create the project and solution. Though not strictly necessary, I like to rename the automatically generated MainWindow class to Shell due to convention.</p>



<p class="wp-block-paragraph">Next, we need to create an Infrastructure project as a class library. If the Shell is our canvas, the Infrastructure project is the palette.&nbsp;It holds all classes, resources, and constants that will be shared between the Shell and the various modules, as well as all the interfaces for the shared services.</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Infrastructure.png" alt="New Infrastructure Project" title="New Infrastructure Project"/></figure>



<p class="wp-block-paragraph">Delete any classes created and add a reference to this project to your Shell project. Next, add a folder called &#8220;Constants&#8221; to the Infrastructure project. To this new folder add a new public static class called &#8220;RegionNames&#8221; and add the constants shown below. If this were a real application rather than an instructive one, the naming conventions for the regions would probably reflect the functional purpose of the injected modules for each region.</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C#</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>namespace Infrastructure.Constants
{
    public static class RegionNames
    {
        public const string MENU_REGION = "MenuRegion";
        public const string SHELL_BOTTOM_REGION = "ShellBottomRegion";
        public const string SHELL_MIDDLE_REGION = "ShellMiddleRegion";
        public const string SHELL_TOP_REGION = "ShellTopRegion";
    }
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #569CD6">namespace</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">Infrastructure</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Constants</span></span>
<span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">static</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">class</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">RegionNames</span></span>
<span class="line"><span style="color: #D4D4D4">    {</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">const</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">string</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">MENU_REGION</span><span style="color: #D4D4D4"> = </span><span style="color: #CE9178">&quot;MenuRegion&quot;</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">const</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">string</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">SHELL_BOTTOM_REGION</span><span style="color: #D4D4D4"> = </span><span style="color: #CE9178">&quot;ShellBottomRegion&quot;</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">const</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">string</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">SHELL_MIDDLE_REGION</span><span style="color: #D4D4D4"> = </span><span style="color: #CE9178">&quot;ShellMiddleRegion&quot;</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">const</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">string</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">SHELL_TOP_REGION</span><span style="color: #D4D4D4"> = </span><span style="color: #CE9178">&quot;ShellTopRegion&quot;</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">    }</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<p class="wp-block-paragraph">Now we add the Prism libraries to our Shell. Right click on the PrismSample project and select &#8220;Manage NuGet Packages&#8230;&#8221; Click on the &#8220;Browse&#8221; tab and type &#8220;prism.unity&#8221; in the search box. Select the &#8220;Prism.Unity&#8221; package and install it.</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/PrismUnity.png" alt="Adding Prism and Unity Libraries via NuGet" title="Adding Prism and Unity Libraries via NuGet"/></figure>



<p class="wp-block-paragraph">Finally, we implement the Shell XAML. Our layout will be pretty straightforward with a logo in the upper left corner, the menu region below that, and the other three regions taking up the right side.</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">XAML</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>&lt;Window x:Class="PrismSample.Shell"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:prism="http://www.codeplex.com/prism"
        xmlns:constants="clr-namespace:Infrastructure.Constants;assembly=Infrastructure"
        mc:Ignorable="d"
        Title="Prism Sample Application" Height="900" Width="1600" Icon="Resources/DMC Wheel Transparent Background.ico">
    &lt;Grid>
        &lt;Grid.ColumnDefinitions>
            &lt;ColumnDefinition Width="Auto" />
            &lt;ColumnDefinition />
        &lt;/Grid.ColumnDefinitions>
        &lt;Grid Grid.Column="0" Margin="50, 25" >
            &lt;Grid.RowDefinitions>
                &lt;RowDefinition Height="Auto" />
                &lt;RowDefinition />
            &lt;/Grid.RowDefinitions>
            &lt;Image Grid.Row="0" Margin="10,20" Source="Resources/Small_jpg.jpg" />
            &lt;ContentControl Grid.Row="1" prism:RegionManager.RegionName="{x:Static constants:RegionNames.MENU_REGION}" />
        &lt;/Grid>
        &lt;Grid Grid.Column="1" Background="#FFE7E7E7">
            &lt;Grid.RowDefinitions>
                &lt;RowDefinition />
                &lt;RowDefinition />
                &lt;RowDefinition />
            &lt;/Grid.RowDefinitions>
            &lt;ContentControl Margin="30, 30, 30, 0" Grid.Row="0" prism:RegionManager.RegionName="{x:Static constants:RegionNames.SHELL_TOP_REGION}" />
            &lt;ContentControl Margin="30, 15" Grid.Row="1" prism:RegionManager.RegionName="{x:Static constants:RegionNames.SHELL_MIDDLE_REGION}" />
            &lt;ContentControl Margin="30, 0, 30, 30" Grid.Row="2" prism:RegionManager.RegionName="{x:Static constants:RegionNames.SHELL_BOTTOM_REGION}" />
        &lt;/Grid>
    &lt;/Grid>
&lt;/Window></textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #808080">&lt;</span><span style="color: #569CD6">Window</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">x:Class</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;PrismSample.Shell&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #9CDCFE">xmlns</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #9CDCFE">xmlns:x</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #9CDCFE">xmlns:d</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;http://schemas.microsoft.com/expression/blend/2008&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #9CDCFE">xmlns:mc</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #9CDCFE">xmlns:prism</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;http://www.codeplex.com/prism&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #9CDCFE">xmlns:constants</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;clr-namespace:Infrastructure.Constants;assembly=Infrastructure&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #9CDCFE">mc:Ignorable</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;d&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #9CDCFE">Title</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;Prism Sample Application&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Height</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;900&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Width</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;1600&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Icon</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;Resources/DMC Wheel Transparent Background.ico&quot;</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Grid</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Grid.ColumnDefinitions</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">ColumnDefinition</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Width</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;Auto&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">ColumnDefinition</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Grid.ColumnDefinitions</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Grid</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Grid.Column</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;0&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Margin</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;50, 25&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Grid.RowDefinitions</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">RowDefinition</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Height</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;Auto&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">RowDefinition</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Grid.RowDefinitions</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Image</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Grid.Row</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;0&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Margin</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;10,20&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Source</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;Resources/Small_jpg.jpg&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">ContentControl</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Grid.Row</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;1&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">prism:RegionManager.RegionName</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;{x:Static constants:RegionNames.MENU_REGION}&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Grid</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Grid</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Grid.Column</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;1&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Background</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;#FFE7E7E7&quot;</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Grid.RowDefinitions</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">RowDefinition</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">RowDefinition</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">                </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">RowDefinition</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Grid.RowDefinitions</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">ContentControl</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Margin</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;30, 30, 30, 0&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Grid.Row</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;0&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">prism:RegionManager.RegionName</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;{x:Static constants:RegionNames.SHELL_TOP_REGION}&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">ContentControl</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Margin</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;30, 15&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Grid.Row</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;1&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">prism:RegionManager.RegionName</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;{x:Static constants:RegionNames.SHELL_MIDDLE_REGION}&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">ContentControl</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Margin</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;30, 0, 30, 30&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Grid.Row</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;2&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">prism:RegionManager.RegionName</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;{x:Static constants:RegionNames.SHELL_BOTTOM_REGION}&quot;</span><span style="color: #D4D4D4"> </span><span style="color: #808080">/&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Grid</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Grid</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Window</span><span style="color: #808080">&gt;</span></span></code></pre></div>



<p class="wp-block-paragraph">If we were to try to execute our program now, we&#8217;d throw an exception indicating a missing service location provider. Prism is designed that when it needs to access a component of the application (in this case the RegionManager) it doesn&#8217;t initialize the component directly but instead delegates this task to a ServiceLocator. So how do we let Prism know what ServiceLocator to use? That&#8217;s where the next component of our application comes in.</p>



<h2 class="wp-block-heading" id="h-the-bootstrapper">The Bootstrapper</h2>



<p class="wp-block-paragraph">If the Shell is the canvas, the Infrastructure project is the palette, the modules are the images to paint, and Prism is the paintbrush, that would make the Bootstrapper the medium of this tortured artistic metaphor. The Bootstrapper connects the Shell to the Prism services and the Dependency Injection container. Unique for each application, it typically inherits from the abstract classes UnityBootstrapper or MefBootstrapper, depending upon DI container used. (If using a different DI container from either Unity or MEF, there is a base abstract bootstrapper class from which all bootstrap classes inherit. The developer would create their own class which inherits that base class and customize it for that particular DI container.) Since we are using Unity for our DI, we inherit from UnityBootstrapper for our class, thereby letting Prism do most of the difficult work for us.</p>



<p class="wp-block-paragraph">The first thing we need to do once we&#8217;ve created our Bootstrapper is override the CreateShell() method. CreateShell() lets you specify the top-level window for a Prism application. You can either create the shell object yourself, or let the ServiceLocator do it. We’ll opt for the latter.</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C#</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>protected override DependencyObject CreateShell()
{
    return ServiceLocator.Current.GetInstance&lt;Shell>();
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #569CD6">protected</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">override</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">DependencyObject</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">CreateShell</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">return</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">ServiceLocator</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">Current</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">GetInstance</span><span style="color: #D4D4D4">&lt;</span><span style="color: #4EC9B0">Shell</span><span style="color: #D4D4D4">&gt;();</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<p class="wp-block-paragraph">Next, we override InitializeShell(). InitializeShell() is where you run any initialization steps you need to ensure the Shell is ready to be displayed. After that, you set the Shell as the application’s main window and show it.</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C#</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>protected override void InitializeShell()
{
    Application.Current.MainWindow = (Shell)this.Shell;
    Application.Current.MainWindow.Show();
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #569CD6">protected</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">override</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">void</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">InitializeShell</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #9CDCFE">Application</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">Current</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">MainWindow</span><span style="color: #D4D4D4"> = (</span><span style="color: #4EC9B0">Shell</span><span style="color: #D4D4D4">)</span><span style="color: #569CD6">this</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">Shell</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #9CDCFE">Application</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">Current</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">MainWindow</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">Show</span><span style="color: #D4D4D4">();</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<p class="wp-block-paragraph">This is all we have to do with the Bootstrapper for now. We will be returning to it frequently over the course of this series. Here&#8217;s the complete class.</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C#</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>using System.Windows;
using Microsoft.Practices.ServiceLocation;
using Prism.Unity;

namespace PrismSample
{
    /// &lt;summary>
    /// Initializes Prism/Unity components and services
    /// &lt;/summary>
    public class Bootstrapper : UnityBootstrapper
    {
        /// &lt;summary>
        /// Make main window class as Prism shell
        /// &lt;/summary>
        protected override DependencyObject CreateShell()
        {
            return ServiceLocator.Current.GetInstance&lt;Shell>();
        }

        /// &lt;summary>
        /// Set the application's window to the current shell and display it
        /// &lt;/summary>
        protected override void InitializeShell()
        {
            Application.Current.MainWindow = (Shell)this.Shell;
            Application.Current.MainWindow.Show();
        }
    }
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">System</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Windows</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">Microsoft</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Practices</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">ServiceLocation</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">Prism</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Unity</span><span style="color: #D4D4D4">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #569CD6">namespace</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">PrismSample</span></span>
<span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #6A9955">    /// </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #6A9955">    /// Initializes Prism/Unity components and services</span></span>
<span class="line"><span style="color: #6A9955">    /// </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">class</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">Bootstrapper</span><span style="color: #D4D4D4"> : </span><span style="color: #4EC9B0">UnityBootstrapper</span></span>
<span class="line"><span style="color: #D4D4D4">    {</span></span>
<span class="line"><span style="color: #6A9955">        /// </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #6A9955">        /// Make main window class as Prism shell</span></span>
<span class="line"><span style="color: #6A9955">        /// </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">protected</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">override</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">DependencyObject</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">CreateShell</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">        {</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #C586C0">return</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">ServiceLocator</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">Current</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">GetInstance</span><span style="color: #D4D4D4">&lt;</span><span style="color: #4EC9B0">Shell</span><span style="color: #D4D4D4">&gt;();</span></span>
<span class="line"><span style="color: #D4D4D4">        }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A9955">        /// </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #6A9955">        /// Set the application&apos;s window to the current shell and display it</span></span>
<span class="line"><span style="color: #6A9955">        /// </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">protected</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">override</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">void</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">InitializeShell</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">        {</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #9CDCFE">Application</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">Current</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">MainWindow</span><span style="color: #D4D4D4"> = (</span><span style="color: #4EC9B0">Shell</span><span style="color: #D4D4D4">)</span><span style="color: #569CD6">this</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">Shell</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #9CDCFE">Application</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">Current</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">MainWindow</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">Show</span><span style="color: #D4D4D4">();</span></span>
<span class="line"><span style="color: #D4D4D4">        }</span></span>
<span class="line"><span style="color: #D4D4D4">    }</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<p class="wp-block-paragraph">On a side note, if we were using MEF for our dependency injection container, we&#8217;d add one more override to the Bootstrapper:&nbsp;ConfigureAggregateCatalog(). We&#8217;d then add a new AssemblyCatalog consisting of our Bootstrapper&#8217;s assembly to MEF&#8217;s AggregateCatalog inside that method.</p>



<p class="wp-block-paragraph">All that’s left is to let WPF know that we want the Bootstrapper to be our startup class. First we remove the StartupUri attribute from App.xaml.</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">XAML</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>&lt;Application x:Class="PrismSample.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    &lt;Application.Resources>         
    &lt;/Application.Resources>
&lt;/Application></textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #808080">&lt;</span><span style="color: #569CD6">Application</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">x:Class</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;PrismSample.App&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">             </span><span style="color: #9CDCFE">xmlns</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">             </span><span style="color: #9CDCFE">xmlns:x</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">Application.Resources</span><span style="color: #808080">&gt;</span><span style="color: #D4D4D4">         </span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Application.Resources</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #808080">&lt;/</span><span style="color: #569CD6">Application</span><span style="color: #808080">&gt;</span></span></code></pre></div>



<p class="wp-block-paragraph">Then in App.xaml.cs we override OnStartup() as follows:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C#</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>using System.Windows;
namespace PrismSample
{
    /// &lt;summary>
    /// Interaction logic for App.xaml
    /// &lt;/summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            new Bootstrapper().Run();
        }
    }
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">System</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Windows</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #569CD6">namespace</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">PrismSample</span></span>
<span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #6A9955">    /// </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #6A9955">    /// Interaction logic for App.xaml</span></span>
<span class="line"><span style="color: #6A9955">    /// </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">summary</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #569CD6">public</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">partial</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">class</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">App</span><span style="color: #D4D4D4"> : </span><span style="color: #4EC9B0">Application</span></span>
<span class="line"><span style="color: #D4D4D4">    {</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #569CD6">protected</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">override</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">void</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">OnStartup</span><span style="color: #D4D4D4">(</span><span style="color: #4EC9B0">StartupEventArgs</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">e</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">        {</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #569CD6">base</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">OnStartup</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">e</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #569CD6">new</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">Bootstrapper</span><span style="color: #D4D4D4">().</span><span style="color: #DCDCAA">Run</span><span style="color: #D4D4D4">();</span></span>
<span class="line"><span style="color: #D4D4D4">        }</span></span>
<span class="line"><span style="color: #D4D4D4">    }</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<p class="wp-block-paragraph">And now our application is ready to run. Granted, it doesn&#8217;t do much at this point, mainly because we haven&#8217;t loaded any modules. We&#8217;ll start adding those in <a href="/latest-thinking/blog/id/9298/a-properly-pleasing-prism-primer--part-3-modules">Part 3: Modules</a>.</p>



<p class="wp-block-paragraph">The solution files and source code for this part can be downloaded by clicking below</p>



<div class="wp-block-file"><a id="wp-block-file--media-7b1784d8-8cd4-4d5f-a1bb-41026f64b8ce" href="https://static.dmcinfo.com/wp-content/uploads/2025/06/PrismSample.zip">PrismSample</a><a href="https://static.dmcinfo.com/wp-content/uploads/2025/06/PrismSample.zip" class="wp-block-file__button wp-element-button" download aria-describedby="wp-block-file--media-7b1784d8-8cd4-4d5f-a1bb-41026f64b8ce">Download</a></div>



<h2 class="wp-block-heading" id="h-a-properly-pleasing-prism-primer-the-parts">A Properly Pleasing Prism Primer &#8211; The Parts:</h2>



<p class="wp-block-paragraph"><a href="/latest-thinking/blog/id/9282/a-properly-pleasing-prism-primer--part-1-an-introduction">Part 1:&nbsp; An Introduction</a><br>
<a href="/latest-thinking/blog/id/9295/a-properly-pleasing-prism-primer--part-2-the-shell">Part 2:&nbsp; The Shell and Bootstrapper</a><br>
<a href="/latest-thinking/blog/id/9298/a-properly-pleasing-prism-primer--part-3-modules">Part 3:&nbsp; Modules</a></p>



<p class="wp-block-paragraph"><a href="https://static.dmcinfo.com/services/application-development/desktop-application-development/c-net/">Learn more about DMC&#8217;s .NET application development services.</a></p>
<p>The post <a href="https://static.dmcinfo.com/blog/25160/a-properly-pleasing-primer-tutorial-for-wpf-prism-part-2-the-shell-and-bootstrapper/">A Properly Pleasing Primer Tutorial for WPF Prism &#8211; Part 2:  The Shell and Bootstrapper</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>A Properly Pleasing Primer Tutorial for WPF Prism &#8211; Part 1:  Introduction</title>
		<link>https://static.dmcinfo.com/blog/25239/a-properly-pleasing-primer-tutorial-for-wpf-prism-part-1-introduction/</link>
		
		<dc:creator><![CDATA[DMC]]></dc:creator>
		<pubDate>Fri, 02 Sep 2016 13:01:42 +0000</pubDate>
				<category><![CDATA[PC Application Development]]></category>
		<category><![CDATA[C# .NET Application Development]]></category>
		<category><![CDATA[MS Visual Studio/.NET]]></category>
		<guid isPermaLink="false">https://static.dmcinfo.com/blog/25239/a-properly-pleasing-primer-tutorial-for-wpf-prism-part-1-introduction/</guid>

					<description><![CDATA[<p>The usage of design patterns is situational. Their purpose is to reduce the overall complexity of an application or to replace unfamiliar complexity with manageable equivalents. For a sufficiently simple application, however, using patterns is often overkill. Even more so if the design pattern itself isn&#8217;t familiar to the developers that will be maintaining the [&#8230;]</p>
<p>The post <a href="https://static.dmcinfo.com/blog/25239/a-properly-pleasing-primer-tutorial-for-wpf-prism-part-1-introduction/">A Properly Pleasing Primer Tutorial for WPF Prism &#8211; Part 1:  Introduction</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph">The usage of design patterns is situational. Their purpose is to reduce the overall complexity of an application or to replace unfamiliar complexity with manageable equivalents. For a sufficiently simple application, however, using patterns is often overkill. Even more so if the design pattern itself isn&rsquo;t familiar to the developers that will be maintaining the code. The paradoxical upshot is usage of the pattern can actually increase the complexity if the application is simple.</p>

<p class="wp-block-paragraph">For example, let&rsquo;s say you&rsquo;ve written a GUI that consists of a single button whose purpose when clicked is to produce a bell sound providing conditioned stimulus to make the user drool. (On the internet no one knows you&rsquo;re a dog, after all.) The whole application can and should be handled completely by a single View. Usage of a pattern such as Model-View-Controller, Model-View-Presenter, or Model-View-ViewModel would be a sloppy mess, much like the aforementioned user&rsquo;s screen, keyboard and mouse.</p>

<p class="wp-block-paragraph">But rarely are applications that simple. Most will benefit from at least some pattern use, and as complexity grows, the advantages of patterns greatly exceed the overhead of implementing them. For applications using Windows Presentation Foundation (WPF), Silverlight, Windows 10 UWP, or Xamarin Forms as their user interface framework, this is where Prism can help.</p>

<h2 class="wp-block-heading">What is Prism?</h2>

<p class="wp-block-paragraph">Prism, a project originally developed by Microsoft patterns and practices and now under the stewardship of the <a href="http://www.dotnetfoundation.org/" target="_blank">.NET Foundation</a>, is a collection of resources implementing common design patterns and architectural support for loosely-coupled modular applications. It saves you the time, energy and complexity it would take to implement these resources yourself. To quote Prism&rsquo;s own documentation:</p>

<p class="wp-block-paragraph"><i style="mso-bidi-font-style:normal"><span style="font-size:11.0pt;line-height:107%;font-family:&quot;Calibri&quot;,sans-serif;
mso-ascii-theme-font:minor-latin;mso-fareast-font-family:Calibri;mso-fareast-theme-font:
minor-latin;mso-hansi-theme-font:minor-latin;mso-bidi-font-family:&quot;Times New Roman&quot;;
mso-bidi-theme-font:minor-bidi;mso-ansi-language:EN-US;mso-fareast-language:
EN-US;mso-bidi-language:AR-SA">Prism provides guidance designed to help you more easily design and build rich, flexible, and easy-to-maintain Windows Presentation Foundation (WPF) desktop applications. Using design patterns such as Model-View-ViewModel (MVVM), Composite View, and Event Aggregator that embody important architectural design principles helps you create a modular application&mdash;using loosely coupled components that can evolve independently. These types of applications are known as composite applications&hellip;.It is expected that the application will evolve significantly over its lifetime in response to new requirements and business opportunities. In short, these applications are &quot;built to last&quot; and &quot;built for change.&quot; Applications that do not demand these characteristics may not benefit from using Prism.</span></i></p>

<p class="wp-block-paragraph">&ldquo;Prism&rdquo; was the early codename for the <em>Composite Application Library (CAL)</em> which was later renamed to <em>Composite Application Guidance for WPF and Silverlight</em>. No doubt realizing that they were headed towards a progression of increasingly long, complex and awkward to verbalize naming conventions, Microsoft took a step back and redubbed it &ldquo;Prism.&rdquo; Prism provides many different functionalities, including modular programming support, event aggregation, shared services, logging, command processing (including built-in implementation of the ICommand interface), deploying to multiple frameworks, support for both Model-View-Presenter (MVP) and Model-View-ViewModel (MVVM) presentation patterns (including built-in implementation of INotifyPropertyChanged) and dependency injection (DI) and inversion of control (IoC). For DI/IoC, Prism includes built-in support for both MEF and Unity, but can be configured to use other DI containers if desired. And since each asset is largely independent from the other assets, an application developer is free to use as many or as few of them as they want, depending on the needs of the application. While this blog series will touch on most of the functionality Prism provides, it will concern itself primarily with combining Prism with WPF, MVVM and Unity for UI framework, presentation model and dependency injection, respectively.</p>

<h2 class="wp-block-heading">Where is Prism?</h2>

<p class="wp-block-paragraph">The Prism libraries and their source code are available on <a href="https://github.com/PrismLibrary/Prism" target="_blank">GitHub</a>. The libraries are also available through NuGet. As of this blog post, the current version is 6.2.0.</p>

<p class="wp-block-paragraph">Documentation can be found also at GitHub or through <a href="https://msdn.microsoft.com/en-us/library/ff921153(v=pandp.40).aspx" target="_blank">MSDN</a>. The documentation is well written, thorough and organized and also includes some sample projects. However, it&rsquo;s also fairly long and detailed, so this blog series will try to provide you with enough of an overview to get you started working with Prism without having to read the entire documentation start to finish. As a result, there are a considerable number of documented features that I won&apos;t be addressing in this series.</p>

<h2 class="wp-block-heading">How Do I Use Prism?</h2>

<p class="wp-block-paragraph">In all honesty, considering all the functionality Prism provides, a full answer to that question exceeds what one can be reasonably expected to accomplish in a blog series. However, if you want a good foundation from which you can start programming with Prism and/or better absorb the documentation already out there, this series has that in spades. It will walk you through a step-by-step creation of a fairly simple WPF application that uses MVVM and Unity and touches upon a significant portion of the more commonly used functionality Prism provides. Each part of the blog will build on the previous part, and source code will be available, along with solution and project files. (Visual Studio 2015; .NET Framework SDK 4.6.2)</p>

<p class="wp-block-paragraph">Note that this series assumes the reader has at least a passing familiarity with C#, WPF, and the MVVM design pattern.</p>

<p class="wp-block-paragraph">So without further ado, we continue on to&nbsp; <a href="https://static.dmcinfo.com/latest-thinking/blog/id/9295/a-properly-pleasing-prism-primer--part-2-the-shell">Part 2:&nbsp; The Shell and Bootstrapper</a></p>

<h2 class="wp-block-heading">A Properly Pleasing Prism Primer &#8211; The Parts:</h2>

<p class="wp-block-paragraph"><a href="https://static.dmcinfo.com/latest-thinking/blog/id/9282/a-properly-pleasing-prism-primer--part-1-an-introduction">Part 1:&nbsp; An Introduction</a><br />
<a href="https://static.dmcinfo.com/latest-thinking/blog/id/9295/a-properly-pleasing-prism-primer--part-2-the-shell">Part 2:&nbsp; The Shell and Bootstrapper</a><br />
<a href="https://static.dmcinfo.com/latest-thinking/blog/id/9298/a-properly-pleasing-prism-primer--part-3-modules">Part 3:&nbsp; Modules</a></p>

<p class="wp-block-paragraph"><a href="https://static.dmcinfo.com/latest-thinking/blog/articletype/categoryview/categoryid/136/c-net-application-development">Learn more about DMC&apos;s .NET application development services.</a></p>
<p>The post <a href="https://static.dmcinfo.com/blog/25239/a-properly-pleasing-primer-tutorial-for-wpf-prism-part-1-introduction/">A Properly Pleasing Primer Tutorial for WPF Prism &#8211; Part 1:  Introduction</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Querying the Active Directory</title>
		<link>https://static.dmcinfo.com/blog/25759/querying-the-active-directory/</link>
		
		<dc:creator><![CDATA[Christopher Olsen]]></dc:creator>
		<pubDate>Tue, 26 Apr 2016 13:26:52 +0000</pubDate>
				<category><![CDATA[Web Application Development]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[MS Visual Studio/.NET]]></category>
		<guid isPermaLink="false">https://static.dmcinfo.com/blog/25759/querying-the-active-directory/</guid>

					<description><![CDATA[<p>While developing a .NET application, you may find that you need to access data that is stored in the Active Directory (AD). In these cases, if you’re not experienced with querying the AD, you may be tempted to create a copy of the data you need into a SQL database – however, this would amount [&#8230;]</p>
<p>The post <a href="https://static.dmcinfo.com/blog/25759/querying-the-active-directory/">Querying the Active Directory</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">While developing a .NET application, you may find that you need to access data that is stored in the Active Directory (AD). In these cases, if you’re not experienced with querying the AD, you may be tempted to create a copy of the data you need into a SQL database – however, this would amount to unnecessary data redundancy.</p>



<p class="wp-block-paragraph">Fortunately, pulling data from the AD and using it in your application is much easier than you might think, and allows you to maintain data integrity by keeping your data in just one place. Also, SharePoint developers will be happy to learn that the AD can be queried from within a SharePoint add-in with the same code that I&#8217;ll be sharing here.</p>



<p class="wp-block-paragraph">First, let’s have a brief review of what the Active Directory (AD) is:</p>



<p class="wp-block-paragraph">The AD is, for the purpose being discussed here, basically a database, except that its storage is hierarchical in nature. The data it stores typically regards the different components in a computer network. For example, a very common use of the AD is to store various pieces of information about a user (email address, name, phone number, title/job description, etc.) It may also contain data about user groups, such as the marketing department, IT, etc.</p>



<h2 id="h-getting-started" class="wp-block-heading">Getting Started</h2>



<p class="wp-block-paragraph">The first thing you’ll need to do is figure out what your AD domain path is. <span style="line-height: 1.6;">Also, if you&#8217;re querying the AD from within a SharePoint add-in, you&#8217;ll need to make sure that the user under which the Add-in web service is running has the proper permissions to access the AD.</span></p>



<p class="wp-block-paragraph">And finally, it should be said at this point that you’ll need to use a few .NET assemblies that you may have never touched before:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C#</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>using System.DirectoryServices;

using AD = System.DirectoryServices.ActiveDirectory;
using AP = System.DirectoryServices.Protocols;
using AM = System.DirectoryServices.AccountManagement;</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">System</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">DirectoryServices</span><span style="color: #D4D4D4">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">AD</span><span style="color: #D4D4D4"> = </span><span style="color: #4EC9B0">System</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">DirectoryServices</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">ActiveDirectory</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">AP</span><span style="color: #D4D4D4"> = </span><span style="color: #4EC9B0">System</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">DirectoryServices</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Protocols</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">AM</span><span style="color: #D4D4D4"> = </span><span style="color: #4EC9B0">System</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">DirectoryServices</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">AccountManagement</span><span style="color: #D4D4D4">;</span></span></code></pre></div>



<h2 id="h-example-getting-user-info" class="wp-block-heading">Example: Getting User Info</h2>



<p class="wp-block-paragraph">Something I often find myself having to do is get a list of all users in the AD, along with some piece of data associated with them. In this example, we&#8217;ll be building a Dictionary that associates each user with the name of their manager.</p>



<p class="wp-block-paragraph">First, let&#8217;s show you the code, then we&#8217;ll explain it.</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/code1.png" alt="Active Directory querying code"/></figure>



<p class="wp-block-paragraph">After we’ve declared an empty dictionary, and retrieved our current path, we go ahead and create an instance of the DirectoryEntry class, passing our domain path as a parameter to its constructor. It should be noted that most of these DirectoryServices classes implement the IDisposable interface, meaning that we need to make sure we dispose of them after we’re done using them. To make this easier, of course, we utilize “using” statements here, so that our unmanaged resources automatically get released.</p>



<p class="wp-block-paragraph">Next, we pass our DirectoryEntry as a parameter to the DirectorySearcher class constructor. The DirectorySearcher class’ main purpose is to allow us to query the AD.</p>



<p class="wp-block-paragraph">Now that we have our DirectorySearcher instance, the wise thing to do is to use a filter to narrow our search results – if we skip this step, we sacrifice performance. So we assign to the DirectorySearcher’s Filter property a string that represents an LDAP query. In this case, our query “(&amp;(objectCategory=User)(objectClass=person))” returns only objects that are in the User category and that implement the “person” class.</p>



<p class="wp-block-paragraph">Now, for a given AD object, there can be dozens or even hundreds of properties. So to save on performance, we only want our query to return those properties which we’ll actually be using. To do this, we add property names as strings to the PropertiesToLoad property of our DirectorySearcher. Finally, we execute the query by calling the FindAll method of the DirectorySearcher. This returns a SearchResultCollection.</p>



<p class="wp-block-paragraph">Iterating through this collection gives us access to SearchResult class instances. To avoid a null reference exception, I like to ensure that each SearchResult actually has the properties that I’m looking for. After that, getting our values is a simple matter of accessing the Properties property of the SearchResult with a string indexer. In this case, both are properties are simply strings, so I only want to return element zero, but if the property I was querying were an array, I would probably be iterating through it or doing some other operation.</p>



<p class="wp-block-paragraph">So the final step here is to add the value of our user’s display name and the value of the “manager” property as a KeyValuePair in my Dictionary, and move on to the next SearchResult. Once we’ve iterated through the entire collection, we can simply return our Dictionary.</p>



<p class="wp-block-paragraph"><a href="https://static.dmcinfo.com/services/digital-workplace-solutions/microsoft-consulting-services">Learn more about our Microsoft Consulting Services</a></p>
<p>The post <a href="https://static.dmcinfo.com/blog/25759/querying-the-active-directory/">Querying the Active Directory</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Connecting Custom Applications to the Factory Floor</title>
		<link>https://static.dmcinfo.com/blog/26086/connecting-custom-applications-to-the-factory-floor/</link>
		
		<dc:creator><![CDATA[Jon Carson]]></dc:creator>
		<pubDate>Fri, 18 Dec 2015 10:31:29 +0000</pubDate>
				<category><![CDATA[PC Application Development]]></category>
		<category><![CDATA[PLC]]></category>
		<category><![CDATA[Siemens PLC]]></category>
		<category><![CDATA[Web Application Development]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C# .NET Application Development]]></category>
		<category><![CDATA[Custom Applications]]></category>
		<category><![CDATA[MS Visual Studio/.NET]]></category>
		<guid isPermaLink="false">https://static.dmcinfo.com/blog/26086/connecting-custom-applications-to-the-factory-floor/</guid>

					<description><![CDATA[<p>DMC has expertise in both industrial and PC-based software development. In other words, we do a great deal of projects involving PLCs; but we also write plenty of complex PC-based apps. But my personal favorites are projects that combine the two. We’re seeing them more and more. Don’t get me wrong, off the shelf solutions [&#8230;]</p>
<p>The post <a href="https://static.dmcinfo.com/blog/26086/connecting-custom-applications-to-the-factory-floor/">Connecting Custom Applications to the Factory Floor</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">DMC has expertise in both industrial and PC-based software development. In other words, we do a great deal of projects involving PLCs; but we also write plenty of complex PC-based apps. But my personal favorites are projects that combine the two.</p>



<p class="wp-block-paragraph">We’re seeing them more and more. Don’t get me wrong, off the shelf solutions are great, and should be used wherever they make sense. But sometimes they don’t fit all of the requirements our customers need. Here are some examples I’ve encountered over the past few months where a custom PC app made the most sense in an industrial setting:</p>



<p class="wp-block-paragraph">1.&nbsp;&nbsp; &nbsp;A program that automatically parses CAD drawings of a part, and then sends the resulting data to a PLC.<br>
2.&nbsp;&nbsp; &nbsp;Multiple offsite PLCs sending Ethernet packets over a cellular modem, to a server-side application that received, parsed, and logged the data.<br>
3.&nbsp;&nbsp; &nbsp;A web-based interface that translate data back and forth between a custom SQL server and multiple PLCs.</p>



<p class="wp-block-paragraph">So we’ve established there are situations where a custom app makes sense. But how does one write this type of program? What tools are out there to connect the dots? As it turns out, there are plenty! Here are some of my favorites:</p>



<p class="wp-block-paragraph"><strong><a href="https://github.com/dotnetprojects/DotNetSiemensPLCToolBoxLibrary" target="_blank">Dot Net PLC Toolbox&nbsp;</a></strong><br>
Believe it or not, there’s actually a pretty strong community of .NET developers interested in interfacing to PLCs. One of my favorite open-source libraries is the Dot Net PLC Toolbox. This in-depth, free library allows .NET apps to parse PLC projects, as well as communicate, read tags, and go online. Last year I personally was involved with using this toolbox to create an open-source <a href="https://github.com/boriz/s7-diff-merge" target="_blank">S7 Source Control Utility</a>.</p>



<p class="wp-block-paragraph"><strong>InGear Drivers </strong><br>The guys over at InGear have created easy-to-use .NET drivers for Siemens, OPC, and more. Sure, there are free tools available, but sometimes it’s nice to pay for a product just so you have a support team to rely on when you need them.</p>



<p class="wp-block-paragraph"><a href="http://jamod.sourceforge.net/" target="_blank"><strong>Jamod</strong></a><br>
Most of our development is built on .NET, but sometimes client requirements dictate another language like Java. This is where a library like Jamod can be handy. Jamod is a Java library written for Modbus (serial, TCP, or UDP). Since Modbus is such an open protocol, this library makes it easy to connect your Java application to PLCs, drives, smart IO, and more.</p>



<p class="wp-block-paragraph"><a href="https://support.industry.siemens.com/cs/document/108716692/tia-portal-openness%3A-introduction-and-demo-application?dti=0&amp;lc=en-WW" target="_blank"><strong>TIA Portal Openness</strong></a>&nbsp;<br>
For Siemens PLCs in particular, there are official tools available to the interested programmer. With the latest version of TIA Portal, Siemens released an API used to interface with PLC programs. This code library allows developers to “automate” their code development by exporting, modifying, and importing TIA projects. I was pretty familiar with their old software, the <a href="/latest-thinking/blog/id/8446/automating-siemens-s7-and-simotion-tasks-using-c-net">Command Interface</a>, and was excited to see them release a tool for Portal as well.</p>



<p class="wp-block-paragraph">Learn more about DMC&#8217;s <a href="/services/embedded-development-and-embedded-programming"><strong>.NET and automation intelligence capabilities</strong></a>.&nbsp;</p>
<p>The post <a href="https://static.dmcinfo.com/blog/26086/connecting-custom-applications-to-the-factory-floor/">Connecting Custom Applications to the Factory Floor</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
