0
votes

I am newbie in using Prism. I have created a sample application to understand it. I have some queries on, how it is working.

Question 1:

    public class HelloModuleCls : IModule
    {
        IRegionManager regionManager;
        IUnityContainer container;

        public void Initialize()
        {
        RegisterViewAndServices(); // Injecting occurs here

            if (regionManager.Regions.ContainsRegionWithName("ViewHolder"))
            {
                regionManager.Regions["ViewHolder"].Add
                (
                ***container.Resolve().View***
                );
            }
        }

        protected void RegisterViewAndServices()
        {
            //since angular brace is not appearing, I am using ( , )....
            container.RegisterType(IHelloView, HelloViewUC)();
            container.RegisterType(IHelloViewModel, EmployeeVM)();
        }
    }

    public class EmployeeVM : INotifyPropertyChanged, IHelloViewModel
    {        
        public EmployeeVM(IHelloView targetview)
        {

        }
    }

Upon hitting the line, container.Resolve().View, the ctor of the VM, gets executed with, view type got injected in the param "targetview".

1. So, what will happen behind the scene, when that line got a hit...?

Question 2: Project Name:- HelloModule (Another Silvelight Class Library referred in the startup Silverlight Application)

    public class HelloModuleCls : IModule
    {
        public HelloModuleCls(IRegionManager rm, IUnityContainer um)
        {
        regionManager = rm;
        container = um;
        }
    }    

(Shell.Xaml) (In Startup Silverlight Application)

<ContentControl Prism:RegionManager.RegionName="ViewHolder" Grid.Row="0">
</ContentControl>

This Module is in another project. I am having the Region in the startup project. I have seen that, in the ctor of the HelloModuleCls, the region got which is used in the Startup project, got injected perfectly...

2. So, how the prism is passing those regions..... Is it like, once the region got created, then it will be injected to all the available Modules ctor or some other concept.

May I kindly know, how this is working out, So I can able to understand more.

Thanks in advance.

1

1 Answers

1
votes

Answer 1: it resolve the one view, normally you want to register views with some key to be able to differentiate them.

Answer 2: it's the other way round, the regions exist in the application and the modules use them. They need to somehow know the name of the region, of course.

Unsorted comments:

  • RegisterType<ISomeInterface, OneOfItsImplementations>() lives in the Microsoft.Practices.Unity namespace, so add using Microsoft.Practices.Unity; to "see the angular brace appearing"
  • use something like regionManager.RegisterViewWithRegion("MyRegion", typeof(AView)) to make the view automatically appear in the region
  • to switch views in a region, have a look at prism's navigation features, like RegisterTypeForNavigation and RequestNavigate
  • the view uses the viewmodel, not the other way round. The viewmodel normally doesn't know about the view.