I dont't get it.....

Sep 27, 2008 at 10:02 AM

Lately I’ve been working with porting my existing application to prism. It has been a painful experience mostly because, as I believe, I don’t understand how to use prism.

My existing application is heavy based on use of generics to avoid repeating code, Unity for dependency injection and other stuff I read about (NHibernate).

Prism would give me a way to modularize my application keeping memory footprint low and apply a better testing strategy. I also hoped to be able to rewrite some parts of the UI to achieve better isolation between logic and look and feel.

So far this has been a complete failure and I have reached the state where I wonder,,,, why bother. The reason is that my code seems to be more and more cluttered with dependences instead of modularized, I keep repeating my code, etc  …….    sadly to say  “ugly”

Could anyone give me a hint how to use prism………  the samples I have seen on the internet seems to be “to simple” and I unable to “interpolate” the examples to something useful for me.

My application then …….

The base is a collection of Persons. I have two views of persons, first PersonCollection and the PersonCRUD. Then I have a two other collection of objects both with two views:  ObjecACollection, ObjectACRUD, ObjectBCollection and ObjectBCrud. Both ObjectA and ObjectB contains references to Person, and ObjecA contains a reference to ObjectB. ObjectA is a quite complex object. (the real application has a lot more views)

Having this specification, how would you guys set up a prism project to for best modularity, avoid to repeat  code and have good testability and extensibility???



Sep 28, 2008 at 3:05 PM
Hi Lassel,  I blogged on a similiar topic HERE.  Perhaps this blog entry combined with the message thread it references (from this forum) will help.

Sep 28, 2008 at 3:37 PM
I think my problem is more of how to reuse Views. From my PersonCollection view I will obvious use my PersonCrud View to be able to manage Person objects. Also, from my ObjectAColletion and ObjectBCollection I also would like to use PersonCrud. If PersonCollectio, ObjectACollection and ObjectBCollection is different modules, where do I put PersonCrud.

I cant se that your example adresses this topic.

Sep 29, 2008 at 5:25 AM
Edited Sep 29, 2008 at 5:29 AM
Hi Lassel, you would put PersonCrud in it's own project/module.   In the flash demo, that I provided on our previous discussion HERE, I showed how we could move an RSS Feed list (view) from one region to another in a Visual Studio style view (SDMSMain).  The RSS Feed view is in it's own project which I use in the SDMSMain view; I could just as easily reused it in any other module.   

For your convenience I scaled down the application shown in the flash demo to applicable components and replaced the SCSF style events (attributes) with CompositeWPF events => http://www.global-webnet.net/flash/SDMSV1.0.0.0.zip  perhaps this will get you closer to what your looking for?

Note: the MainShell, SDMSMain and RSSFeed have no knowledge of each other - only region names.  

Sep 29, 2008 at 5:51 PM
I am sorry to say that I can not see how moving a View from one region to another region would help me.
If I put the PersonCrud in a Module of its own, the view of PersonCrud is hard coded to a specific region. How do you access it from other modules without building dependecis to it? ObjectA and ObjectB would like to have their own instances of the view. Another problem,,, the other modules using PersonCrud maby would have the PersonCrud view in a specic view that is a part of their own "View".

As I sad earlier, I am not a pro,,,   and I am missing something here....

Sep 29, 2008 at 8:20 PM
Edited Sep 29, 2008 at 8:23 PM

Where there is a will, there is a way :)

Note below I changed my RSSFeedView.cs code behind so that there is no longer a hard coded reference to MainWorkspace; it now becomes the using modules responsibility to set the Region name, via RSSRegion, prior to resolving the view:

private void listBox1_SelectionChanged(object sender,
    SelectionChangedEventArgs e)
// BillKrat.2008.09.29
// Get region name from container (configured in module)
//IRegion mainRegion = RegionManager.Regions["MainWorkspace"];

    string regionName = Container.Resolve<string>("RSSRegion");
    IRegion mainRegion = RegionManager.Regions[regionName];

    RSSViewer view = (RSSViewer)mainRegion.GetView("Viewer");

    if (view == null)
// If we want to remove the View we'll need to name it
        mainRegion.Add(Container.Resolve<RSSViewer>(), "Viewer");


I then updated my SDMSMain's MainModule.cs as follows:

protected override void RegisterViewsAndServices()
// BillKrat.2008.09.29
// Set region name at module level
    string RSSRegion = "MainWorkspace";
    Container.RegisterInstance<string>("RSSRegion", RSSRegion);

// Add view to region
    IRegion mainRegion = RegionManager.Regions[RegionNames.MainRegion];

Program still works - no hard coded references - are we getting closer?