web 2.0

II. Prism solution based on the Biz App Template

A couple words on Silverlight & Modularity

If you browse the web you would find few articles on modular RIA Services applications.
Even if you visit the blog of Brad Abrams and open Business Apps Example for Silverlight 3 RTM and .NET RIA Services you will notice the post about Modular Development is not written yet.

This post belongs to RIA Services MVVM Prism LoB Application series, read Introduction post to find out more about it.

So what can we actually do? Look for the Prism (Composite Application Library), MEF and Caliburn framework.

I find all of them very promising, MEF is focusing on design of extensible applications and components and is still in development (Preview, April 2010); Caliburn is a framework to support the development in many areas, but I find it also too “fresh” and not as well documented as Prism from Patterns&Practices team.

Prism + WCF RIA Services

I chose Prism for my application, since it support modular development and provides some great features as UnityContainer, ServiceLocator, Commanding and other stuff. You should be aware of some design patterns in order to understand how these works.

Solution

Solution structure

I didn’t start from scratch and created a new solution with Silverlight Business Application Template. The Silverlight project will be our Shell. After that I created the Infrastructure project.

Then you can add a new Silverlight Module by creating a Silverlight Application project and made some changes in order to make it working as Prism Module.
Important is to host it in your Web project and to enable RIA Link to that Web project; disable the create TestPage option.
Then you have to create some folder (let’s say Web/Resources) and add there resources from Web project “as link” (the same links are in Shell project).

My first idea was to create separate Web project for each module, where Services+Metadata for coresponding Module could be placed, with one EF Model in different solution, but I didn’t make it work, so If you do, please let me know.

When I was on a half-way I finally found one example of Prism and .NET RIA Services so you may study how it is done there (it helped me, as well).

If you are interested in how I implemented Prism in my WCF RIA application have a look on the source code.

I recommend to read the well written documentation of Prism. Some QuickStarts are also included in the library.

Some code examples

Now, lets see how to register a domaincontext in a module so it behaves like a singleton if you’ll follow some conventions. This is Initialize method from my ProjectsModule.cs class, which implements the IModule interface and holds as an initializator of the module.

public void Initialize()
{
    //Register Domain Contexts which are being used in the module
    unityContainer.RegisterType(new InjectionConstructor());
    unityContainer.RegisterType(new InjectionConstructor());

    //Locate the base module view
    ProductsModuleView pmView = this.unityContainer.Resolve();
    //Locate the Main Shell region and add module view to it
    IRegion region = regionManager.Regions[RegionNames.MainRegion];
    region.Add(pmView, pmView.GetType().Name);
    region.Activate(pmView);

    //Register main module views with the Products's module region
    region = regionManager.Regions[MODULE_NAME + RegionNames.ModuleRegion];
    regionManager.RegisterViewWithRegion(
        MODULE_NAME + RegionNames.ModuleRegion,
        () => this.unityContainer.Resolve());
    regionManager.RegisterViewWithRegion(
        MODULE_NAME + RegionNames.ModuleRegion,
        () => this.unityContainer.Resolve());
}

Let’s have a quick look on a Module Catalog which is placed in file ModuleCatalog.xaml and you can specify there what modules would you like to load, specify dependencies and whether the module should load on demand or immediately as it is available.



    

    

    

    
        
            Products
            Customers
        
    


If you have any questions, append a comment to this post, please.

6 Responses to “II. Prism solution based on the Biz App Template”

  1. [...] This post was mentioned on Twitter by Chris Woodruff and Javier Rodríguez, Brad Abrams. Brad Abrams said: Looks like a good start on modular RIA Services based apps http://bit.ly/bPdW5d [...]

  2. Really enjoyed your post. I’m at a point right now where my SL4 project is getter larger and I need to decide which direction to go. I have looked at PRISM for a few weeks and I really like the module and region manager.

    I’m also a big fan of MEF(have not used it yet). With the inclusion of MEF into the framework in .NET 4 leads me to believe that MEF should be the included into large projects.

    Where my confusion comes in is that I don’t understand. Does MEF provide the “Moudle” and “Region” manger?

    Or do I use both PRISM and MEF?

    Since PRISM was Glenn Block first project then he switched to MEF makes me think PRISM is being left to die.

    Any way, thanks for the post
    Mike Apken

  3. To Mike Apken: Look at this post by Tim Heuer http://timheuer.com/blog/archive/2010/03/29/msdn-radio-follow-up-answers-riaservices-prism.aspx … it looks that Prism v4 will cope with MEF, MVVM and RIA Services as well.
    Great to hear that for me.

  4. Thanks. That did help.

    Looking forward to your next post.

  5. Dude,

    Yours could’ve been an interesting project to follow. Having spent twenty minutes trying to resolve all the broken/missing refereces, I gave up.

    Include all the DLLs, including your fancy Telerik DLLs, in your downloadable package, and you’ll be golden. Until such time, I ain’t interested.

  6. Excelent example Lukas. Looking foward from reading the next articles

    foobar: i dont see any telerik control. The missing References are from Teleco.*.dll which is the solutions base name.