Use MVC Custom Model Binder?

I have an MVC application that I am writing. Multiple instances of the same page will need to be opened, each of which will access different records from the database, these record objects will also have to go through the page stream before finally being updated.

What's the best and most correct way to do this - should / I can create a custom binding device that associates with an object via its unique ID, then create each entry object in the session, updating them as I go through each thread of one page, and then finally calling the update method? Or is there a better way to handle this?

Greetings

MN

+2


source to share


1 answer


Technically it would be possible, but I don't think it's advisable. When you look at the IModelBinder signature, you'll have to jump through some ControllerContext related hoops if you want to be able to access the rest of your application's context (like how to dehydrate objects based on IDs).

Possibly, but so clumsy that you have to consider if it fits right. In my opinion, it is the responsibility of ModelBinder to map the HTTP request data to strongly typed objects. Nothing more and nothing else is a strict cartographer, and trying to do so could violate the principle of single responsibility.



It seems to me that you want an Application Controller - basically a class that organizes the views and state of the underlying model. You can read more about the Application Controller design pattern in Enterprise Application Architecture Patterns .

Since a web application is inherently stateless, you need a place to store the intermediate state of the application. Whether you are using sessions or custom persistent storage depends on the requirements of the application and the overall complexity of the intermediate data.

+2


source







All Articles