c# - MVC Web API Binding Model to a Derived Class -


i looking @ how bind model derived class within mvc web api, issue have think have found 5 ways of doing it...

what have is:

models ->

  • modelbase
  • modela : modelbase
  • modelb : modelbase

controller containers method:

post(modelbase model) {} 

the data posted modela or modelb, want add information http request metadata (think content-type: application/json; type=modela) , based on tell mvc bind posted content either or b.

in code imagine like:

bind(request, bindingcontext) {     // check request headers , then...     bindingcontext.modeltype=typeof(modela);      // let framework continue doing thing deserializing content     base.bind(request, bindingcontext); } 

how has else this? or how recommend doing this?

i've seen parameterbinding, imodelbinder, mediatypeformatter, etc. mvc great, hard think hook should use...

edit:

to add more information, modelbase become interface, , there hundreds of concrete classes.

it going cqrs: command , concretecommanda, concretecommandb, these pushed off dispatcher, don't want making action each command, central action receive these commands, deserialize them correct type , forward them on.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -