CSLA used in MVP or MVVM

CSLA used in MVP or MVVM

Old forum URL: forums.lhotka.net/forums/t/8519.aspx


TEden posted on Thursday, February 11, 2010

Hello,

I am looking for an example app that anyone my point me to where CSLA is implemented in an MVP or MVVM presentation pattern.  I feel confident enough, thanks to Rocky's explanations in posts and his video series (thanks for that btw) that the data access can be abstracted and de-coupled from the business layer, however I am struggling to find a decent example where the presentation logic has been done the same.

I am architecting a solution that will require not only webform clients, but also xaml clients and I would really like to have one business layer coupled loosely to the presentation logic, presentation logic that is ideally not repeated to host multiple views.  I am very new to CSLA, and the existing application is a mess of classic asp, asp.net and zero concept of layer or separation of concerns.  I have to fix all that and provide a solution that is capable of adapting to new ui platforms of the future. 

My first reaction was MVP, I have have implemented supervising controller solutions many times in the past and thought a passive view would easily solve this problem, however the more I learn about MVVM the more I am liking this approach.  IMO, it's a much more familiar model I can teach my developers as the VM is really just an adapter to the view, much like other .Net concepts.  I also feared that I would have to be forced to re-factor smart business objects into an anemic model, but I don't think that is the case any longer.  I am concerned though I will not be able to support webforms and xaml (or other) without duplicating presentation logic just to adapt to multiple views though at the same time, perhaps seperate VM's is actually a good design since the VM is not abstracting the Model, but instead it's purpose is to abstract the view? 

So in short, does anyone have any thoughts on how best to leverage CSLA, be domain driven and have a clear SoC specifically at the presentation layer?

Is it possible to create a presentation layer that is view independent and at the same time leverage concepts like databinding while maintaining a clear separation of concerns and is MVVM, MVP or another pattern best suited for this?  Perhaps I am asking too much, I mean if I can solve this we could be almost future proof as technologies change.  I could really use an example, I know one was requested in a previous post but I did not see an answer.

thank you very much

RockfordLhotka replied on Thursday, February 11, 2010

The challenge I've been facing in building an MVVM sample is two-fold.

  1. MVVM is a pattern, not a UI framework - and you can't really implement the pattern without a UI framework - and I've been hesitant to build out the necessary UI framework elements (and surely don't plan to include them in CSLA)
  2. I've been waiting for the XAML designer in VS10 to mature - though with the RC out now that excuse is no longer valid Wink - because if I do give in and build out the necessary UI framework elements, I want them to work within the context of the VS10 designer, which imposes some constraints on how the View and ViewModel interact, because of the way it generates the XAML and supporting constructs

That said, for the Code Mastery event today I did build a decent start on a VS10 MVVM sample. I'm still trying to figure out some of the idiosyncrasies around the VS10 designer, so while I have a working sample, I'm not real happy because I did have to manually type some XAML - and that's just not right... (imo)

The thing is, an MVC or MVVM UI framework does a lot of work, so the business developer only has to create the M, V, C or VM. The UI framework, at a minimum, must handle message routing, rendering and (in the case of XAML) some enhanced form of commanding. Without these things, you can't get testability of the VM - which is the ultimate goal of using MVVM (or test the C in MVC).

ASP.NET MVC is a good example of a framework that does robust message routing and has a rendering engine (the thing that invokes the controller and renders the view returned by each controller method). A business developer never really thinks about these elements - they are "part of the platform", but they are very real.

No such thing exists in XAML - not natively. So you must either adopt an existing UI framework or build one.

You might (and probably should) choose to adopt an existing UI framework - which means they'll provide those elements, along with constraints on your V and VM (at a minimum) based on the design choices made by the UI framework developer.

For my purposes, I want to deeply understand the nature of these elements, and so my new sample includes simplistic (but functional) message routing and rendering so the VM can be executed outside of a XAML environment (e.g. in a unit testing environment).

I haven't put this sample in svn yet, because I literally just created it, and as I said, I'm not happy with some of how it works - my goal is to avoid manual editing of XAML and I'm just not there yet...

I rather suspect any other UI frameworks you find won't worry about manual editing of XAML - up to VS10 you had to edit XAML because there was no designer. But I hope that over the next several months we'll start to see UI frameworks that build off the VS10 designer concepts, making it possible to build decent business apps without the need to see or manipulate XAML by hand.

Heinz replied on Tuesday, April 13, 2010

Hi,

there is a very good example at

http://beyondthispoint.blogspot.com/2009/02/using-repository-pattern-with-cslanet.html

It's a complete example with a MVP approach, using the Repository Pattern and Unity for Unit Tests.
It shows how to load the CSLA Objects automatically into the Unity Container. There is also UI Testcode, that tests the MVP

The UI is a windows form one, but it may give you a clue how to do it.

Kind regards
Heinz

 

Copyright (c) Marimer LLC