惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
Engineering at Meta
Engineering at Meta
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 聂微东
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 三生石上(FineUI控件)
T
Tailwind CSS Blog
Apple Machine Learning Research
Apple Machine Learning Research
Hugging Face - Blog
Hugging Face - Blog
爱范儿
爱范儿
博客园 - 司徒正美
人人都是产品经理
人人都是产品经理
Jina AI
Jina AI
博客园 - 叶小钗
雷峰网
雷峰网
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - Franky
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
阮一峰的网络日志
阮一峰的网络日志
量子位

博客园 - 四眼蒙面侠

OpenAI 宣布破解纳维—斯托克斯:证明之外,为什么吵翻了? # 基于 Claude Code 的 Moltbook 心跳脚本:让你的 AI Agent 全自动参与社区 Moltbook 要把事情高大: AI 机器人的"身份证"来了 电视黑屏了,还在听吗?聊透 LG 智能电视隐私争议 Chrome 今年第六个零日漏洞:V8 认错了对象,而且真的有人在打 GLM-5.3 开放权重:该买机器把 AI 搬回家吗? 苹果没料到:Mac mini 怎么成了企业 AI 香饽饽 同一个模型,两道安全闸门:克劳德寓言 5.1 真正变了什么 AI 推荐的软件,到底是谁推荐的? GPT-6 Astra:破纪录之后,AGI 真的来了吗? OpenAI 的智能体,在德国老 wiki 上开了一块作弊黑板 一串会清空手机的密码,为什么可能换来五年牢狱? 作业高分,考试却跌两成:AI到底帮你学了什么? GitHub 上的第二张假面:一个大学生如何拦住会骗人的 AI 从十一到九十九,AI 创业公司为什么都爱叫 Labs? 卖十块板子,先交一千欧?欧洲包装新规为何难倒小卖家 玄戒 O3 跑分追上苹果,是真突破还是数字游戏? 当 AI 开始拆你的摄像头:桌面外设的安全边界正在消失 你用 AI 裁我,我就造个 AI CEO? 英伟达为什么想花 130 亿美元买下 Hugging Face? AI 已经会设计分子,为什么新药还没变快? 模型越强,为什么我们反而越不敢放手? DeepSeek Harness:为什么要把智能体的所有部件都做成插件 AI 让代码变便宜以后,工程师真正昂贵的是什么 加密的思考,也会被偷走吗?这篇论文真正发现了什么 一群模型,各干各的活:Nemotron 3.5 Lightning 和 Switchyard 到底解决什么 它真的“懂”你吗?用一杯咖啡理解大语言模型 买书、扫描、然后销毁:AI 训练的旧书去哪儿了? 七十GB与八十TB:当个人和科技巨头站上不同的法律天平 只读到小学五年级的 AI,能自己悟出高等知识吗?
【转】ASP.NET MVC 3 Service Location, Part 8: Value Provi...
四眼蒙面侠 · 2011-01-25 · via 博客园 - 四眼蒙面侠

Value Providers

ASP.NET MVC 2 introduced a new method to find value providers: the ValueProviderFactory class. Value providers are used by the model binding system in MVC to populate the values of model objects. MVC includes value providers for several common value sources (including query string, form, route data, uploaded files, and JSON postbacks); MVC Futures includes several mode (including cookies, server values, session values, and temp data values). In ASP.NET MVC 3, we have made ValueProviderFactory instances findable via the dependency resolver.

Disclaimer

This blog post talks about ASP.NET MVC 3 Beta, which is a pre-release version. Specific technical details may change before the final release of MVC 3. This release is designed to elicit feedback on features with enough time to make meaningful changes before MVC 3 ships, so please comment on this blog post or contact me if you have comments.

Implementing ValueProviderFactory

Developers who implement this class must provide an implementation of GetValueProvider which, given a controller context, optionally returns an instance of a class which implements the IValueProvider interface. The developer may also choose to return null if there is no appropriate value provider or values.

For reference purposes, there are several implementations of ValueProviderFactory in the MVC and MVC Futures source code. For a simple example, see the pair of classes: QueryStringValueProviderFactory and QueryStringValueProvider.

Implementing IValueProvider

Developers who implement this interface provide implementations of two methods: ContainsPrefix and GetValue. The former method is used to determine if there are any values in the provider with the given prefix (so the model binding system knows when to stop recursively binding). The latter method is used to get the value for a specific key.

There are two implementations of IValueProvider (NameValueCollectionValueProvider and DictionaryValueProvider) will accept collections of values to be used for the value provider implementation. Most of the value providers in the MVC source code actually derive from one of these two base classes.

Location: ValueProviderFactory

This is a “multiply registered” style service introduced in MVC 2. The static registration point for this service is atValueProviderFactories.Factories for non-DI users.

The logic in ValueProviderFactoryCollection (which implements ValueProviderFactories.Factories) was updated to consult the dependency resolver, calling GetServices(typeof(ValueProviderFactory)) and adding any services found to the list of statically registered services. Value providers all collaborate to provide values for model binding, with a “first one to provide the value wins” strategy, so registration order is important. The factories found in the dependency resolver will always run in the order they are returned from the resolver (and before the statically registered value provider factories); similarly, the value providers will be consulted in the order they are returned from the factories.

What’s Next?

Next up we’ll talk about Model Binders.