添加自定义ValueProviderFactories到ASP.NET MVC3? [英] Adding custom ValueProviderFactories to ASP.NET MVC3?

查看:157
本文介绍了添加自定义ValueProviderFactories到ASP.NET MVC3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找,试图添加的protobuf ValueProviderFactory到MVC3,这样我可以挑出来的MIME类型和反序列化的原始数据转化为行动参数的对象。我还可以用它来改变默认的JSON序列化。

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.

看着 JsonValueProviderFactory.cs 这应该不会太困难,但工厂似乎都硬codeD。

Looking at JsonValueProviderFactory.cs this shouldn't be too difficult, but the factories all appear to be hard-coded.

有关的protobuf我也许可以做一些与IValueProvider,但是我还没有检查还没有什么MVC3做时,临危的MIME类型应用程序/ x-的protobuf的

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?

更新

我发现的博客贴子,讨论有关创建 IValueProvider 。然后,它提到了底部,这改变了周围的MCV2。他改成了一个 ValueProviderFactory ,并呼吁:

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());

但在MVC3该属性为只读。

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!

我已经做了一些更多的搜索的今天,的这个博客文章似乎表明, DependencyResolver 会发现,继承 ValueProviderFactory 任何类。我使用MEF的依赖关系,所以我可以再补充一个出口属性,它会得到自动获取。

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.

我现在有一个<一个href="http://stackoverflow.com/questions/6902885/creating-mvc3-valueproviderfactories-that-require-type-information">further问题编写定制ValueProviderFactory为protobuf网。

I now have a further issue writing a custom ValueProviderFactory for protobuf-net.

这篇关于添加自定义ValueProviderFactories到ASP.NET MVC3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆