View / Presenter Objects not Constructed

Topics: Prism v2 - WPF 3.5
Dec 17, 2009 at 6:41 PM

Hello All,

I have included thee code blocks below:

1. A module class

2. The XAML for the module's view

3. The shell XAML that defines my one and only region

As annotated in   omment form in the code below, the module does load and the  view registration code is reached. I am, however, seeing that neither my view nor presenter constructors run. Is anybody able to see what I'm doing wrong? Please let me know if more context is needed.

using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Unity;
using ModuleName.Views.ModuleNameView;
using SolutionName;

namespace ModuleName
{
   public class ModuleName: IModule
   {
      public ModuleName(IRegionManager regionManager, IUnityContainer unityContainer)
      {
         RegionManager = regionManager;
         UnityContainer = unityContainer;
      }

      public void Initialize()
      {
         RegisterViewsAndServices();

         // THIS LINE IS REACHED.
         RegionManager.RegisterViewWithRegion(
            RegionNames.MainRegion,
            () => UnityContainer.Resolve<IModuleNamePresenter>().View
         );
      }

      protected void RegisterViewsAndServices()
      {
         UnityContainer.RegisterType<IModuleNameView, ModuleNameView>();
         UnityContainer.RegisterType<IModuleNamePresenter, ModuleNamePresenter>();
      }

      private IRegionManager RegionManager { get; set; }
      private IUnityContainer UnityContainer { get; set; }
   }
}

 

 

 

<UserControl x:Class="ModuleName.Views.ModuleNameView.ModuleNameView"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   HorizontalAlignment="Stretch" VerticalAlignment="Stretch">

   <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
      <TextBlock Text="ModuleNameView" Background="Red" FontSize="24"
         HorizontalAlignment="Center" VerticalAlignment="Center"
         Height="Auto" Width="Auto">
      </TextBlock>
   </Grid>
</UserControl>

 

 

 

<Window x:Class="SolutionName.Shell"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:cal="http://www.codeplex.com/CompositeWPF"
   xmlns:local="clr-namespace:SolutionName"
   Title="SolutionName" Height="500" Width="800">

   <ContentControl
      x:Name="m_mainRegion"
      cal:RegionManager.RegionName="x:Static local:RegionNames.MainRegion}"
      HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
   </ContentControl>
</Window>

Thanks,

Dave

 

Dec 18, 2009 at 5:57 PM

Hello All,

I suspect I may not have given enough context as there have been no responses. For the full, buildable, and runnable solution (requiring VS 2008, .NET 3.5 SP 1), please download the following:

http://www.theese.com/SolutionName.zip

This is a very simple Composite WPF app with one module and one view. As stated in my original post, neither the view's constructor nor the presenter's constructor runs. Is anybody able to tell why?

Thanks!

Dave