将自定义 ValueProviderFactories 添加到 ASP.NET MVC3?

发布于 2024-11-27 06:42:26 字数 687 浏览 0 评论 0原文

我试图尝试将 Protobuf ValueProviderFactory 添加到 MVC3,以便我可以选择 MIME 类型并将原始数据反序列化为操作参数的对象。我还可以使用它来更改默认的 Json 序列化器。

查看 JsonValueProviderFactory.cs,这应该不会太困难,但工厂似乎都是硬编码的。

对于 Protobuf,我也许可以使用 IValueProvider 做一些事情,但我什至还没有检查 MVC3 在收到 MIME 类型的 application/x-protobuf 时会做什么。

我以正确的方式处理这件事吗?

更新

我发现这篇博客文章其中讨论了创建 IValueProvider。然后它在底部提到这在 MCV2 周围发生了变化。他将其更改为 ValueProviderFactory 并调用:

ValueProviderFactories.Factories.Add(new HttpCookieValueProviderFactory());

但在 MVC3 中此属性是只读的。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

骄兵必败 2024-12-04 06:42:26

事实证明它不是只读的,您可以按如下方式添加提供程序:

ValueProviderFactories.Factories.Add(new MyValueProviderFactory());

如果我自己检查的话我就会知道这一点!

我今天做了更多搜索,这篇博客文章似乎表明DependencyResolver将找到继承ValueProviderFactory的任何类。我使用 MEF 进行依赖项解析,因此我只需添加一个 Export 属性,它就会被自动选取。

我现在有一个进一步的问题为protobuf-net编写自定义ValueProviderFactory 。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文