Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Mar 06, 2012 02:19 PM by LittleClive
Mar 06, 2012 10:33 AM|LINK
Returning a BookDTO from the ActionMethod combined with some kind of transformation in a MediaTypeFormatter is probably the best approach in my situation... It will break the (yet non-existing in ASP.NET Web API) documentation feature of the 'WCF Web API'
though, since this will state BookDTO as the return type of my ServiceMethod, exposing it to the public.... but maybe the documentation feature of the APS.NET Web API, will take this in account or make it possible to override it.
Mar 06, 2012 11:20 AM|LINK
Yes losing the anticipated documentation is a bit of a shame - I did raise this during the preview at:
If we want this we'll have to do something bespoke - which I don't think is too much of a problem since our transform interface is fairly clean - no base class.
In case it helps, one other thing I did was provide a wrapper for IEnumerable<BookDTO> to RepresentationListV1<BookV1> - the wrapper just knows about IEnumerable<> and RepresentationListV1<> and is automatically created with the correct inner transformer.
I've also heard you can do some clever stuff with
https://github.com/AutoMapper/AutoMapper but I'm feeling a slight ickiness about using it.
Mar 06, 2012 02:19 PM|LINK
I just found a subtle but important difference of using:
The former will pick version specific MediaTypeFormatters meaning that internally you don't need to be switching on version number to pick a transformer. The latter will match on all versions (since the version parameter is not taken into consideration)
and therefore require a more complicated internal mechanism.
Another advantage of the former is that it works with clients that don't understand or deal with parameterised Accept headers very well.
I haven't looked to see if the selection mechanism could have been modified to take version parameters into consideration but there is an IFormatterSelector interface that you could implement and inject via a DependencyResolver.