Is MVC a good idea for a real world, complex, line of business application?

Is MVC a good idea for a real world, complex, line of business application?

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


JCardina posted on Wednesday, November 23, 2011

I just started reading the CSLA 4 and MVC ebook and looked at the sample project and it's making me think MVC is not the way to go for anything non trivial with complex forms and business objects with many fields and child collections.

Right now my gut feeling is that webforms, as flawed as it is, is still the better technology for complex business applications but I want to double check as I've yet to find any evidence anyone is using it for anything large and complex.

Is anyone actually using MVC with a complex business application with a lot of objects and fields? 

olawal replied on Wednesday, November 23, 2011

OMG yes , once you really start using MVC you will actually HATE webforms , I have build lots of mvc applications with really large and complex databases such s dating websites as well as social networks and the MVC pattern and the absolute separation of concerns really simplifies your life as a developer.

Just the fact you are not tied to the archaic page lifecyle really makes things far more conistant and though it might seem you do write a bit more code, when it comes down to it you will be able to to manage the code far better than user controls and page events in Asp.net.

now the caveat to this is I would NOT use CSLA.net personally as somone being new to MVC due to the learning curve of just CSLA and MVC combined.  I would use EntityFramework 4.1 and POCO objects for my business layer and DB as well as use the build in validation you get on models with MVC.  Honestly I really don't think you need CSLA with MVC  for example to apply custom buisness rules add  you can use dataanotations  i.e [Require] , or [IsNumeric] to decorate your model objects and the repository does not have to know anything about how you validate.

Here is an excellent link from microsoft on how do do alot of things in MVC natively rather than using frameworks like CSLA

http://www.asp.net/mvc/tutorials/validation-with-the-data-annotation-validators-cs

** CSLA is excellent but in your case due to the learning curve of MCV combined with CSLA at the same time I would start with MVC and get that design pattern down and then use CSLA to extent it **

just my 2 cents

 

JCardina replied on Wednesday, November 23, 2011

Whups, I worded that wrong, I'm *very* familiar with CSLA 4 at this point and have used an older version for years and there's no doubt I'm using CSLA 4.  I'm porting a winform / asp.net webform projects to WPF / (potentially) MVC 3 (4).

My only issue is with MVC which I'm hazy on.  After looking at Rocky's ebook and the example project tracker the pages rendered looked *extremely* simplistic to me.  I started looking around for any other MVC samples and they *all* are very simplistic.  Basically going to one page, editing one business object with very few properties etc.

By contrast my old asp.net webform app I'm porting has in part, one very complex form that includes multiple business objects, contains dozens of fields and has several child collections.  Nothing I see as an example in MVC is remotely as complex looking, in fact they are almost always examples of online stores or some other mainly read only type site.

In Rocky's sample project tracker there are 5 separate view .cshtml files for each type of business object.  (Create, Delete, Edit, Details, Index) In Project tracker this is only about 5 objects, in my app it's more like 50 objects. 

On the face of it this seems like I'll need 250 different views at minimum.  In my current version of the asp.net app with the same objects I have only one page for each object and it handles all the edit, update and what have you.  I don't know if this is just Rocky's style he's using and I can do something more efficient or I'm looking at this wrong or...?

This scares me off.  From what I can determine MVC almost seems to expect that a page will only be used for editing a single, simple object, not a complex collection of objects as is often the case in a business application.  Also that it really expects one simple way of doing everything and doesn't support many different pages that are completely different from each other (i.e. a complex business task, a schedule form, etc etc).

I'm worried that mvc is only for very simplistic mostly read only scenarios and that you don't get a lot of control over the page design.

Maybe there's a book or website or something that can show what can be done with MVC but I"m not seeing it yet.

olawal replied on Wednesday, November 23, 2011

ohhh i got you, actually where MCV shines is with large complex objects like you are talking about

MVC supports partial views so you can use a single view with multiple partial child views to handle  different operations.

or you can do it exactly how you do it in ASP  but I find it cleaner to use a partial view for different operations and the partial views are very simple to implement.

In regard to complex objecs , you can create what I term (propaly wongly) viewmodel

bascially a complex object that can conists on as many objects as you want to safeley serialize if you are creating an N tier app.

 ie you could have a profiledata viewmodel

[Seralizable]

public profileDataviewmodel

{

public UserRole

public list<photos>  MyPhotos {get;set;}

public  list<Accounts>  MyAccounts {get;set;}

public list<friends>  photos MyFriends {get;set;}

etc etc as compex as you see fit

}

your perant view then would inherit that ProfileDataViewmodel

and your can do stuff like this in your view

<% for each ProfiledataViewModel.MyPhotos %>

{

some operattiosn here , or maybe iteratate or list the complex objects or format them as a datagrid or photos or something

}

say you want to do an operation on just the Accounts you can pass as much or as little of the viewmodel you want to the partial view . i.e If I had an editaccoutns partial page I could have it inherit the Accoutunts Object maybe and pass just that to that view which could be a modal popup or whatever I want etc etc.

complex objects are what makes MVC the most fun , the reason he is using multiple pages for different operations is becase it is far more testtable and easier to isolate error with pages or in page code than one huge page that does everything but using a viewmodel you can have you complex objects available to any page or pages you want.

hope that helps,

p.s i just randomly typed in the code so ignore my syntax sorry

JCardina replied on Wednesday, November 23, 2011

Ahhh!  That *does* help.  Rocky covered that in the book but I glossed over it when skimming through it, now it makes a lot more sense and the partial views sounds like what I'm missing.

Very helpful, thank you, I appreciate it!

Cheers!

olawal replied on Wednesday, November 23, 2011

sure thing I love MVC and every programmer I know either beginner or expert loves the pattern its just makes "sense" is what they all say

glad i was able to help

Copyright (c) Marimer LLC