I'm new to MVVM and I'm struggling to make a decision on which MVVM framework to adopt. We use CSLA extensively on the app server side, but not currently within our WinForms client apps which are 2-tier apps using an SOA architecture - i.e. loosely coupled from the server. Some of these apps are a bit long in the tooth, and due for update and enhancement - but we will keep the SOA architecture (i.e. we will not adopt the n-tier DataPortal model because we need the loose coupling).
I want to migrate to WPF, Silverlight, WP7 and iOS ultimately - or at least be able to have these platforms included on our roadmap.
I like various aspects of different MVVM frameworks:
* PRISM has built-in MEF and extensibility support which would be ideal - I like the IModule concept.
* MVVM Light seems lightweight, has a less steep learning curve than PRISM and seems to have good inter-view model messaging support.
* Bxf seems to be the easiest of all to adopt and obviously comes with CSLA support out of the box.
Does anyone have any pearls of wisdom, or better still some great code examples of CSLA integrated with MVVM frameworks other than Bxf?
Strategically I want to go in the right direction with this but I must admit that my shortcomings in .NET, WPF and Silverlight are making this a difficult decision!
Given that you're going with a pure SOA architecture, and not using CSLA on the client, the integration with any MVVM framework you choose and CSLA doesn't really matter, because there won't be any. Whichever framework you choose will communicate with your back-end via your SOA interface, not with CSLA.
To be honest, I think you're going to have a tough time choosing an MVVM framework that will work with all those client OS's. iOS is going to be the tough one - none of the popular MVVM frameworks I know of work in iOS (presumably running under Mono) - heck, I don't think Rocky's got all of CSLA working under Mono yet. But if you leave that out, then I think any of the ones you've chosen will work fine. Bxf loses some steam given how you're going to structure your client. Prism is probably the one with the steepest learning curve, because it's trying to do more than the others. It also sometimes gets dismissed purely because it comes from Microsoft, but from what I'm seeing it really isn't all that bad.
Presuming you're OK with a more convention-based approach, you might also look at Caliburn.Micro - based on my very informal research, it seems to be running neck-and-neck with MVVMLight as the "MVVM framework du jour". All of them should work with all the Microsoft UI technologies, though I haven't seen much on Prism and WP7. There could be some issues there, given that WP7 is still basically SL3.
Thanks for your reply Scott - it certainly helps.
I agree that if we are not using CSLA on the client then integration with CSLA is clearly not an issue. I don't want to close the door to using CSLA on the client, because of all the well understood reasons why we all use CSLA. Clearly we would have different objects on client and server side, but that is how we tend to do these clients anyway. Our current 'legacy' apps do not use CSLA because they were built way before we adopted CSLA.
I will definitely have a look at Caliburn.Micro, thanks for the tip.
I am naturally attracted by PRISM simply because it is Microsoft and it uses MEF, and (perhaps) offers guidance as to how things in the composite client area will develop in .NET.
I'm not sure what you mean by "Clearly we would have different objects on client and server side". If you're talking about the normal differences between a server-side CSLA object and a client-side CSLA object for things like Silverlight, then OK. But if you're talking about something else... CSLA's mobile-object concept works because the objects are essentially the same on both client and server. The differences between the objects because of Silverlight concerns are fairly minimal. Anything beyond that, and you may run into issues with the DataPortal.
Obviously, going to a CSLA-based client creates even more issues for iOS - just take a look at what Rocky is doing with MonoDroid and MonoTouch to see some of the issues. I believe he has it working, but I also believe there are some caveats. However, that would also give some extra "oomph" to considering Bxf.
FWIW, there were some Caliburn.Micro-compatible classes posted to the CLSAContrib site recently that are supposed to provide easier integration of the two. So you might take a look at those as well. I haven't seen anything like that for Prism, but I'm betting they wouldn't be all that hard, and given Prism's overall structure, they may not be necessary.
As to your last point... this is purely conjecture/opinion on my part, and perhaps Rocky can step in and flesh out some more detail - he has much better contacts at Microsoft than I do. I wouldn't consider Prism to be indicative of much of anything vis-a-vis Microsoft's "composite client area" strategy. I'm not even sure Microsoft has one, to be honest. The P&P folks' influence on Microsoft's strategic direction hasn't been that big, and I think that was a conscious decision. It's my opinion that Prism was more of a reaction to (a) the negativity surrounding CAB; and (b) everybody going "MVVM wild" but not having an "official Microsoft MVVM framework". That second point is probably the most important, since there are an awful lot of shops that simply won't use anything non-Microsoft (see: Unity - also a P&P creation.) Microsoft has traditionally tried not to develop anything "official" in this area - primarily because they don't want to step on their developer community, but also because doing so has ended up turning off a portion of the market. So if you're expecting portions of Prism to make their way into the .NET framework - well, I might not hold my breath on that.
Scott is correct, although Prism can be very useful and can be taken as broad patterns-based guidance, it is not an official Microsoft product. It is a pseudo-open source project from the Patterns and Practices group. Generally, things from PnP should be viewed like any other open source project. If you are comfortable using open source, you should be comfortable using their stuff, otherwise don't use it.
Clearly you are comfortable with open source, because you use CSLA .NET. And you are looking at numerous MVVM or MVP frameworks (Prism is technically MVP, not MVVM) that are open source.
You might consider that one of the primary benefits of CSLA is that it grants your business domain objects full data binding capabilties. Nobody else does this. By restricting the use of CSLA to the server, you obviously can't take advantage of one of the primary features of the framework. I'm not saying your choice is incorrect, but I thought I should bring this up in case you hadn't considered what you aren't able to leverage :)
Because you are only using CSLA on the server, your choice of client-side UI framework is entirely unaffected by your use of CSLA.
I think all the primary options I'm aware of have been listed already:
If you did decide to use CSLA to create your client-side model objects (even if they are independent from the server objects to maintain an SOA architecture and good decoupling), then your choice of UI framework might be impacted.
In that case you'd probably do what I do, and have your viewmodel objects expose a Model property so the view can bind to the model. This radically reduces the normal (inefficient) code in the viewmodel classes, and leverages the power of CSLA and MVVM together.
To my knowledge all these UI frameworks can support this concept, but I'm told that MVVM Light and Caliburn are easier than Prism. You might also look at the super lightweight Bxf framework (http://bxf.codeplex.com) that I created to support my CSLA demos. It is designed to do the absolute minimum necessary to support the MVVM pattern, and so isn't a complete UI framework. But it might be instructive anyway.
By "Clearly we would have different objects on client and server side" what I mean is that we won't necessarily use the mobile objects capability because of our need for loose-coupling. So we could (hypothetically) have separately developed CSLA object models on client and server side that talk to each other in a loosely coupled way (e.g. using DTOs).
I'm sure you are right about PRISM integration into .NET - perhaps what I mean is that the P&P initiative has been going for some time and has a certain 'staying power' so can (perhaps) be relied upon to be around for a while yet...
I have seen reference to what Rocky is doing in MonoTouch and that is really interesting. I just don't know how he finds the time to do everything he does!
ps. Just seen response from Rocky - thanks for this comprehensive answer. I have tied myself in knots with this for a few days, and I think I'm going to take Scott and Rocky's advice and look again at Bxf. What I really need to get off the ground is minimal 'baggage' so that I can get to grips with the fundamentals - then decide later on whether I need all the 'extras' that PRISM offers.
Hi Chris, I'm also new to MVVM but perhaps a little ahead of you. I've looked at them all and settled on Prism. I think there are a few misconceptions in this thread:
Prism is *not* an MVVM or MVP framework and it isn't tied to MEF at all, any of the frameworks can use MEF or their own rolled approach.
Prism is a *lot* more than that and can happily co-exist with an actual MVVM framework like Cinch or Caliburn. MVVM is more how you use it than any specific framework. The "MVVM" frameworks that exist do so purely to provide assistance with coding MVVM style and it's actually a lot less than you'd think. Mostly convenience stuff like handling modal dialogs and hooking up views and viewmodels etc.
Coding MVVM is more about just doing it that way.
If you are making a large app in a modular manner with traditional slew of app features like logging (for example) and want easy testing etc then prism might be for you. I chose it because there are so many examples and books on how to use it and for the maturity of what it offers. I took a serious look at Caliburn but couldn't find as much info on it.
I have a zillion links to things I found on Prism but probably the single most useful one is a set of Visual Studio templates that will generate a working MVVM application for you using either Unity or MEF (I use MEF, I think Unity is a dead end but a lot of examples use it because it came first for Prism).
[EDIT: Sorry Chris after I posted I realized that for some reason this forum software doesn't automatically turn urls into clickable links as most do now]
Here is a link to those templates, they are very useful because they generate a *working* MVVM application and it's a priceless reference when you're getting started:
Also here is a checklist to follow when making a Prism 4 MVVM application:
And an example of how to make an outlook style view switching Prism 4 MVVM application :
Also the tricky area of Authentication in an MVVM application, this thread contains good info and links:
What you will want to focus on initially if you are coming from anwyhere near where I came from is first all the XAML stuff particularly databinding etc:
And MEF on it's own, here's an excellent simple intro:
And for MEF here is a more detailed overview but not too detailed:
Also if you are going to support 3rd party plugins via MEF or just want to make them as loosely coupled as humanly possible you can go one step further here:
Coming from winforms you can quickly become lost in this stuff and it can seem overwhelming, take it bit by bit and make a few test applications to get the hang of it and it will start to all click.
As for IOS I would recommend strongly you rethink that entirely and instead look at using MVVM with Asp.net MVC and JQuery to do an html 5 interface instead so you can support all the different mobile devices. I know that's an unpopular view here, everyone seems to think there's some value in writing native apps for CSLA LOB applications but people in the trenches disagree completely unless there is a very specific need for a native app.
I've come across something that sounds ideal for that scenario but haven't had a chance to really dig through it yet but you might find it interesting:
Thanks for all of this - I will certainly have a look at your references. The 'authentication' one is of particualr interest, because this does seem tricky to do, and there are very few (virtually none) examples for any of the frameworks of how to do it elegantly. Rocky was kind enough to suggest an approach with Bxf on the Bxf codeplex site here: http://bxf.codeplex.com/discussions/257775
Point taken about PRISM not being an MVVM framework and MEF being a separate thing - down to my ignorance of the subject I'm afraid to say!
Actually once you see the techniques the authentication is the easiest part of all! :)
The main problem I had was continually trying to find fully working examples that reflected a real application. I eventually came to realize it's kind of a wild west frontier for MVVM and you pretty much go with whatever you find works and fulfills the requirements for properly separation of concerns and inversion of control.
I.E. the login: there are so many ways to do this, one way is to have your modules all get a message when a user logs in or out or simply unload all modules on a logout and reload them on a login from the shell etc etc. It's all pretty much up to you.
The big brains that come up with frameworks rarely ever seem to do actual real world application development or at least they don't take the time to make end to end real world samples which makes learning this stuff like doing a treasure hunt.
I think the big thing with MVVM is enabling automated testing of the viewmodel. I've seen several projects where testing wasn't implemented from day one - and then couldn't be implemented later because fundamental mistakes were made in the MVVM framework design or in the viewmodel code.
The thing to remember - and this is what turns the world upside down - is that the viewmodel can't contain any code that relies on knowledge of the view, or of specific UI controls, or of specific UI types. Nor can it display a messagebox or otherwise directly interact with things like the navigation shell.
Do any of those things, and you have created untestable code - and thereby have lost the primary value of MVVM.
I take your point about automated testing Rocky, and this is very much at the top of my list of priorities going forward.
Final two questions:
1. I do like what PRISM offers in terms of extensbility and it is reasonably well documented. Would it make sense, and would it work if I used Bxf as the MVVM framework within a PRISM IModule? Does this even make sense?
2. Same question but using Caliburn.Micro (thanks to Tiago for his reply) - can I use the CSLA integration that it offers, within PRISMs extensibility framework, to code IModules?
Anyone care to help with my question - particularly 1?
I'll answer it if it's not still answered when I get there. As far as I can tell I won't need bxf at all with Prism but right now I'm just working on making a working MVVM app that contains all the stuff I need in terms of the shell and infrastructure as a learning exercise. Once that's done I'll add my CSLA 4.x business objects to the mix and see where that takes me.
This stuff is still too new to find any easy answers out there from what I can tell.
As for number two I think you're mixing up things, MEF provides all the modularity you need if you had read the link I provided about MEF and I'm pretty sure Caliburn has all the MVVM stuff you need so Prism is irrelevant in that scenario.
CSLA basically already works with any MVVM framework, the extensions for caliburn are convenience stuff easily replicated for prism.
I think you're trying to find a bunch of stuff you can plug together and just have a working app, you're not going to find it, none of this stuff is plug and play by any stretch of the imagination.
@ JCardina. I really appreciate your responses, and I have looked at your list of links very closely - thanks very much for taking the time to do this. I have found the 'ready-made' PRISM app with switchable views particularly interesting and useful and am looking to use this as a possible framework within which to go forward.
I realise that there is no plug-and-play stuff available for all of this - as you said in one of your posts this seems a little like a wild frontier!!
Just to add my 2 cents.
Caliburn.Micro has a nice integration with CSLA that is available at http://cslacontrib.codeplex.com/
Raed more about it http://forums.lhotka.net/forums/t/10178.aspx
Copyright (c) Marimer LLC