MarimerLLC / cslaforum

Discussion forum for CSLA .NET
https://cslanet.com
Other
31 stars 6 forks source link

MVC & Complex Objects #635

Closed GreggThelen closed 5 years ago

GreggThelen commented 5 years ago

I've read several blog posts on MVC and CSLA. I've found ways to map a singleton object and a list object in this environment.

I've not seen an example of root objects which may contain child objects, or even, child collections.

Perhaps complicated objects cannot be handled by the CslaModelBinder, which is fine, but then I have to wonder what strategy people use in these circumstances. For example, in one blog post Rocky suggested loading the object into memory and then changing the properties manually which would leave the object in an edited state and in a good place for calling an update.

I understand the disconnected nature of the web means that it is necessary to load an object and edit it in the Action handler - I was just hoping for an easy/tested/reliable way to do this with more complex object graphs.

Perhaps I'm asking too much of the technology? Do you just design around this somehow?

Does anyone out there work with MVC and have experience mapping properties more than one level deep?

rockfordlhotka commented 5 years ago

Most of it comes down to the ability (or not) of MVC to map a complex hierarchy of information into a postback, and then to map that into a set of objects on the server.

Even something simple, like a page that displays an "editable data grid" as a list or table in the browser is quite complex to map back into a collection on the server.

This article shows how to do it with Razor pages, and links to another article about how to do it with MVC.

http://www.lhotka.net/weblog/#a4c606e73-f870-450a-9538-1ac48e9fe439

GreggThelen commented 5 years ago

Rocky, thank you. I found those examples helpful.

I'm trying to make the transition from Silverlight to MVC. As you know, in Silverlight having very complex object graphs was no problem - so having a child object with several child collection objects was really no different than in a WinForms environment. Clearly, this isn't going to be nearly as easy in MVC.

So while handling a single object or a single collection isn't a problem it appears that more complex objects are a problem. I'd like to get some strategy on how people handle those OR do they not attempt that in MVC and use a different technology. Maybe everything is broken into different views so that the object graph, when editing, is never more complex than just a single object or a single collection - I don't know how to approach this scenario.

rockfordlhotka commented 5 years ago

I think for server-side web dev you summed it up - people break the UX into bite-sized chunks that can be posted back with reasonable ease.

For more smart client style experiences people actually write the app to run on the client, using JavaScript/TypeScript/Angular/React and various other client-side frameworks. Until webassembly matures, the moral equivalent to Silverlight is basically TypeScript+Angular for most folks.

GreggThelen commented 5 years ago

Rocky, That comment is very helpful. I thought maybe I was missing something obvious about MVC - it helps to know that it doesn't really play nice with complex object structures. The good news is that the first Silverlight application I'm migrating is very simple (much like your mcmreporting) so a little bit of hacky on a couple of back-end objects is no big deal.

My understanding is that Blazor will allow us to return to the Silverlight model (basically) so I'll dial back to porting simple Silverlight projects to MVC and the more complex ones to WPF as requirements allow until Blazor is a real thing.

Thanks again.