Integrating Prism into existing application

Topics: Prism v2 - WPF 3.5
Mar 30, 2009 at 2:45 PM
I have an existing WPF application that would benefit from integrating Prism into it but I haven't a clue where to start. I can create applications using Prism from the start but the integration is stumping me. Any help? Thanks.
Mar 30, 2009 at 4:30 PM
You can download Prism, which has three source code projects called Composite, Composite.UnityExtensions, and Composite.Wpf. Add the three projects to your solution, and also add them to the references of your own projects wherever needed. Build the three projects first (or in the Build Order dialog, make your own projects dependent on the three CAL projects). Then build your solution. You should be good to go then by using the CAL.

Mar 30, 2009 at 4:43 PM
You are kidding me right? All I have to do is reference the Prism libraries and I can have access to the event aggregator (for instance)? Seems like some form of voodoo... :-)

P Please consider the environment before printing this message. Thank you P
Mar 30, 2009 at 5:30 PM


Although there is not a defined way to integrate your application with Prism, this was one of the main objectives of the Composite Application Library (CAL).  The CAL was designed to be easy to integrate in your existing application and take advantage of its features quickly and gradually as you need them.

I think a good point to start with this task would be following the Hello World Quick start provided with the CAL. Based on its content, you will be able to easily modify your existing application to enable CAL inside it, then you should migrate your current application to take advantage of the different advantages that CAL provides.

Basically, as you will see in the QuickStart, in order to get started, you will need to create a bootstrapper to initialize the Unity Container (assuming you want to use Unity) with the CAL services.

Most likely, as you go forward with the integration, you are going to do things like the following to take full advantage of this Guidance, take into account that all these steps are not required to start using the Prism features in your existing application:

1.       Detect the different application’s logic units and separate each of them in a CAL Module when it is possible. This will allow you to implement Modularity.

2.       Identify each UI part inside your current application and migrate these to be Views inside different Regions.

a.       May use presenters to move the UI logic defined inside the XAML Code Behinds outside these.

b.      May use the Presentation Model (also called MVVM) pattern in the case you are not implementing this yet.

3.       Enable communication between the modules by taking advantage of Event Aggregator, Commands and/or Services.


Please, let me know if this helps.


Ezequiel Sculli

Mar 30, 2009 at 5:45 PM
What I described is how to set up CAL in your solution. As for how to use it, I recommend that you read Composite Application Guidance for WPF, and start with the QuickStart as recommended by Ezequiel Sculli. I also suggest that you start with figuring out how to set up the shell and bootstrapper, and how to load modules as these are necessay steps no matter what Composite WPF features you are going to use in your application.
Mar 30, 2009 at 6:03 PM
Thanks guys. I was really afraid you was going to say something like that.
Mar 30, 2009 at 6:31 PM

You may want to communicate more about your situation and needs, so that people could better help you.

BTW, people are here to help and get help. Better communications are very important to have good understanding on the issues. Using proper words would be helpful for building a better community here, so that people would be able to better help with each other.


Mar 30, 2009 at 6:55 PM
Okay, I am not sure what was unclear. I have and existing application that I would like to integrate Prism into. I do not know where to start doing that. I already know how to create a Prism based application. What I do not know is how you are supposed to go about integrating Prism into an exisiting application. Based on your answer and the answer esculli gave, it would seem to be not an integration but more of a conversion process.
Mar 30, 2009 at 7:36 PM
Edited Mar 30, 2009 at 8:16 PM
waday wrote: > > From: waday > > Okay, I am not sure what was unclear. I have and existing application > that I would like to integrate Prism into. I do not know where to > start doing that. I already know how to create a Prism based > application. What I do not know is how you are supposed to go about > integrating Prism into an /exisiting/ application. Based on your > answer and the answer esculli gave, it would seem to be not an > integration but more of a conversion process.

Hey Chap,

Indeed. I wasn't sure many people actually read the 'existing app' bit of your first email since it also seams you know CAL from other project STARTED with it. I'm no expert (have completed/released one commercial app and one personal app using CAL) but I would first ask about (presuming your existing apps are already WPF) what models you already have in your UI? If you have already used some form of MV* model (Model-View-Presenter/Controller/View-Model etc) your in really good shape to apply CAL to it. If you haven't done that already, it would be where I would start I think. Change your views in the app to use view-models and create some controller classes to apply to them. As I see it that is probably the absolute core of it, if you haven't got this model in the app already, separating things into modules will be more painful. If you have got these models in already your probably using Commands etc already, which have direct companions in CAL with pretty much the same syntax. Then you might want to think about separating things into dlls (with static refs between them) before chopping it up completed and stuffing in the container, bootstrapper and event aggregator.

-- Jammer 
Mar 30, 2009 at 8:23 PM
Thanks Jammer.

Still seems to me that it's less of an integration process and more of a conversion process. Seems to me that it would be just as easy to to do a parallel branch and transfer the non-Prism items to the Prism side and break them up as you go. Unless I am totally missing something important. I am not getting where the "integration" part comes in.
Mar 30, 2009 at 8:28 PM
As far as I can tell your going to have to go through that process if you want it to be a composite app.
Mar 30, 2009 at 9:01 PM
Thanks mate. I was really hoping that I wouldn't have to do that. Seems dangerously close to rewriting. It gives me something to think about anyway. It might just be easier than I think it is.
Mar 30, 2009 at 9:46 PM
No problem!

Actually, it's a lot less painful than you might think.  My personal project SampleSort was originally written as a 'traditional' layered .NET app.  The normal, presentation, DataAccess, Db layers etc ... Only took about 3 weeks hard graft to go from that to CAL ...

Good luck!
Mar 31, 2009 at 9:14 AM
I've had a thought ...

One thing you might want to considering before ripping your app apart is the methods centered around dependency injection.  Ideally you would use constructor DI on an app that was started with CAL.  But there are methods for utilising getter/setter DI called BuildUp()/BuildUp<T>.

That was you might avoid any breaking changes on your classes through not having to change all your default constructors whilst still getting the benefits of the container ...

Hmm ...


Mar 31, 2009 at 2:10 PM
Hey thanks for thinking of me Jammer.

Late yesterday afternoon, I had what I suppose would be called a "Great leap of stupidity" in my thinking. Something you said got the rust out of the cogs in my brain. The application that I was thinking of has an exe module and gets its views from a DLL so basically it already it kind of like a shell. So all I really need to do is to add the bootstrapper and start migrating the other stuff to modules. Turns out to be way easier than I thought for this application. Wish I had thought of it before posting though... grrr. But thanks for getting the ball rolling.
Mar 31, 2009 at 9:16 PM
Sounds more than doable and probably not that painful at all.

That was also my experience and is probably what is meant by Prism being easy to integrate.  If your app design sucks already CAL won't help a jot!!!  HAHA!  Seems like yours should be a doddle however.


Apr 10, 2009 at 3:47 PM
Just for future reference in case someone else has a similar question.

If you have an existing application and want to integrate Prism into it this is one possible scenario.

The first thing to do is to create a bootstrapper as documented in the quickstarts. That gives you access to the container.
From there you can access the services like the RegionManager and the EventAggregator with the ServiceLocator:

    IEventAggregator events = ServiceLocator.Current.GetInstance<IEventAggregator>();

This would allow you to take advantage of the services without having to convert everything over all at once. I hope that helps someone.