In the following post by Rocky http://www.lhotka.net/weblog/RepostFromAnMSDNForumDiscussion.aspx
he references how well Csla can work with the current Microsoft MVC framework.
Conceptually this makes sense and MVC looks very promising for some scenarios, but I am curious
if anyone has done any work with MVC and Csla? If so, any recommendations
such as using MVC Contrib, how about the data binding support, active record
(from a testability perspective) within the MVC framework, etc., and if you
think the current MVC and Csla versions (practically speaking) would be ready
for a production application (or at least when MS does a release with a go live
for MVC)?
Would like to hear people's thoughts/experiences...
Fwiw, my work has been entirely at the proof of concept level - making sure CSLA works as-is with MVC.
MVC has no data binding, so there's no issue there. An MVC View looks very much like 1997 ASP Classic code - a mix of html and <% %> code. The only real difference is that there are some helpers that make it easier to emit some of the html. I could see some CSLA-specific helpers that generate certain CSLA-specific html fragments, specifically around validation, and perhaps around authorization.
MVC is stateless by default, which can impact your object model design. Specifically, to create a stateless object model you must bastardize a "normal" object model and pretty much only create read-only lists of read-only objects, and single editable root objects. That's kind of painful, but has nothing to do with MVC - it is an artifact of being stateless.
The real key is that CSLA objects provide a Model that encapsulates all the business logic. Some MVC purists seem to think this is bad, but I don't think so. What it means is that you create a View that displays the data from the object's properties (if allowed), and a Controller that calls the object's factory and hands the result to the View.
On a postback, the Controller gets the values from the html form and can use the MVC helper (which looks a lot like Csla.Data.DataMapper) to copy the values into the object's properties. Then it calls Save() on the object and that's it. The only catch here is the normal one around being stateless - the html form must have all the property data, even for properties it doesn't display so it can reload the object from scratch.
Alternately, of course, if you can't put all the property data in the html form, you can just reload the object, then put the form values into it and then call Save(). There's a perf hit obviously, but this is a pretty common solution to the stateless issue - and still only requires 3-4 lines of code in the Controller.
So a lingering MVC question that I've had (not necessarily CSLA specific) (mind you I have no experience with MVC outside the Hello World app), if there is no Viewstate or Session, does Authorization have to occur on every request? Normally we stuff the Principal into a Session variable and use it from there all over the place...with MVC are we passing credentials on each request? Or does ApplicationContext still take care of that?
Ryan
Csla.ApplicationContext doesn’t take care of it, no.
If you don’t have Session then you are left with few (all
unpleasant) choices for hydrating your Principal object:
1.
Serialize the Principal into the authentication cookie –
which only works if it is small, because there’s a pretty low size limit
on cookies
2.
Reload the Principal from the database on each page request
3.
Reload the Principal from a file or some other temporary store
of your creation
As you say, this is not a CSLA issue, but rather a stateless web
issue. You can encounter this issue without MVC today – just turn off
Session on your web site and you face the same problem.
I haven’t looked to see if MVC supports Session at all. I
suspect it does though, and if it does, then you’d have the option of
using Session just like you do today in a typical Web Forms app.
Rocky
RockfordLhotka:I haven’t looked to see if MVC supports Session at all. I suspect it does though, and if it does, then you’d have the option of using Session just like you do today in a typical Web Forms app.
I would hope it does but either it's implied that it doesn't or I'm just improperly inferring that it doesn't. It would be an ugly world without SOME kind of state persistance on the web...and no cookies don't count. :-)
I just looked on the forums.asp.net site and there are discussions about sessions and MVC and they are supported.
Session is available through HttpContext:
HttpContext.Session["Key"]
From: webjedi
[mailto:cslanet@lhotka.net]
Sent: Friday, June 13, 2008 11:27 AM
To: Nermin Dibek
Subject: Re: [CSLA .NET] RE: MVC and Csla
RockfordLhotka:
I haven???t looked to see if MVC supports Session at all. I suspect it does though, and if it does, then you???d have the option of using Session just like you do today in a typical Web Forms app.
I would hope it does but either it's implied that it doesn't or I'm just
improperly inferring that it doesn't. It would be an ugly world without
SOME kind of state persistance on the web...and no cookies don't count. :-)
Thanks for the replies, this is very helpful. I will continue to dig into and post anything interesting I come across.
Dear All,
We are in the process of finalizing the use of a framework like CSLA .NET for application development. I proposed CSLA some time ago, and just recently, some of my colleagues are competing with my proposal with the following arguments:
1. We are moving to VS 2008, and there is no need to use a framework like CSLA. The new features of VS 2008 have all the features of CSLA .NET.
2. CSLA is not a Microsoft product, not supported by Microsoft, it is open-source and free, so it has limited support. We should consider a Microsoft alternative like the newly released ASP.NET MVC.
3. We should consider ASP.NET MVC because it is supported by Microsoft and has all the features of CSLA.
I have made very little research about ASP.NET MVC, so I am not sure if the above arguments are correct.
I need your feedback about the above arguments.
Thank you.
Tarek.
Comparing ASP.NET MVC and CSLA .NET is like comparing apples and oranges.
ASP.NET MVC is a UI framework that helps you build web interfaces for your application. I like it quite a lot, and it works very well with CSLA .NET. But it does nothing that CSLA does, and CSLA does nothing that the MVC framework does.
CSLA .NET is a business object framework that helps you build a formal business layer for your application. In the MVC world, the CSLA framework helps you build the "M" (Model).
To directly answer your questions:
1. That is false - nothing new in VS 2008 changes the value of CSLA .NET
2. That is mostly true - CSLA .NET is not a Microsoft product, it has limited support (this forum) and it is free. It is arguably open-source. But there is no Microsoft alternative - they don't have a product that does what CSLA .NET does, which is why I created and continue to maintain CSLA.
3. You probably should consider MVC, but as I note above, the two frameworks are entirely different, and work well together.
Thanks a lot !
So, it looks like MVC will close the loop I was looking for since ever I started this exercise about 1 year ago !
Do you mind if you send me your email contact in case I want to use your reply as a reference, just in case. Probably it may not be a good idea to use this post/forum as a reference.
But, we are now on VS 2005 ... so if we want to use MVC, then we have to upgrade all our PCs and skills to VS 2008, which will involve additional cost/licensing/effort ...etc... correct ?
Tarek.
I prefer to handle dialog through the forum rather than via
direct email. I already get far more direct email than I can manage :)
I don’t know what kind of licensing you have today, and I’m
not a licensing expert. If you have MSDN or an EA I’m sure you get VS
2008 automatically, beyond that I have no idea.
I didn’t find moving from VS 2005 to 2008 to require much
learning. They aren’t that different, though 2008 does have some more
features and capabilities.
I would guess that your learning curve will be mostly with
ASP.NET MVC and CSLA .NET, as you’ll need to learn both frameworks.
Rocky
tarekahf:Do you mind if you send me your email contact in case I want to use your reply as a reference, just in case. Probably it may not be a good idea to use this post/forum as a reference.
Copyright (c) Marimer LLC