I was looking to try and add a Protobuf ValueProviderFactory to MVC3 so that I could pick out the MIME type and deserialize the raw data into objects for action parameters. I could also use this to change the default Json serializer.
Looking at JsonValueProviderFactory.cs
this shouldn't be too difficult, but the factories all appear to be hard-coded.
For Protobuf I may be able to do something with an IValueProvider but I haven't even checked yet what MVC3 does when it recieves an MIME type of application/x-protobuf
.
Am I going about this the right way?
UPDATE
I found this blog post that talks about creating an IValueProvider
. It then mentions at the bottom that this changed around MCV2. He changed it to a ValueProviderFactory
and calls :
ValueProviderFactories.Factories.Add(new HttpCookieValueProviderFactory());
But in MVC3 this property is read only.
It turns out that it is not read only and you can add providers as follows:
ValueProviderFactories.Factories.Add(new MyValueProviderFactory());
I would have know this had I checked myself!
I've done some more searching today, and this blog post seems to suggest that the DependencyResolver
will find any classes that inherit ValueProviderFactory
. I'm using MEF for dependency resolution so I can just add an Export attribute and it'll get picked up automatically.
I now have a further issue writing a custom ValueProviderFactory for protobuf-net.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With