如何找到行为中的输出模型类型?
使用 FubuMVC,我不确定确定当前操作的输出模型类型的最佳方法是什么。我看到可以从中获取当前请求 URL 的不同对象。但这并没有带来很好的解决方案。
从行为中获取当前操作的输出模型类型的最简单方法是什么?
如果这不是一个好的做法,还有什么更好的方法呢?
With FubuMVC, I'm not sure what the best way is to determine the current action's output model type. I see different objects that I could get the current request's URL from. But that doesn't lead to a very good solution.
What's the easiest way to get the current action's output model type from the behavior?
If this isn't a good practice, what's a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,我假设您已经在 StructureMap 中设置了设置对象,并且已经连接了 ISettingsProvider 内容。
最好、最简单的做法就是在视图中提取设置,如下所示:
<%: Get().SomeSettingProperty %>
如果您坚持将这些设置为输出模型上的一个属性,然后继续阅读:
假设您有一个如下所示的设置对象:
然后您有一个如下所示的输出模型:
您需要做一些事情:
连接 StructureMap,以便它将为 Settings 对象执行 setter 注入(因此它会自动将 OutputModelSettings 注入到输出模型的“Settings”属性中。
在 StructureMap 初始化代码(注册表、全局 ASAX、Bootstrapper 等 - 无论您在何处设置容器)中设置 setter 注入策略。
创建您的行为以在输出模型上调用 StructureMap 的“BuildUp()”以触发设置器注入。该行为将是开放类型(即最后)。它可以支持任何类型的输出模型
创建约定来连接行为
在路由部分之后将约定连接到 FubuRegistry 中:
在您的视图中,使用新的设置对象:
注意:我已将其作为工作示例提交到 Fubu 源的 FubuMVC.HelloWorld 项目中。请参阅此提交: https://github.com/DarthFubuMVC/fubumvc/commit/2e7ea30391eac0053300ec0f6f 63136503b16cca
First, I'm assuming you've already got your settings object(s) set up in StructureMap and have the ISettingsProvider stuff already wired up.
The best, simplest thing to do would be just to pull the settings in the view, like this:
<%: Get<YourSettingsObject>().SomeSettingProperty %>
If you insist on having these be a property on your output model, then continue reading:
Let's say you had a settings object like this:
Then you had an output model like this:
You'll need to do a few things:
Wire up StructureMap so that it will do setter injection for Settings objects (so it will automatically inject the OutputModelSettings into your output model's "Settings" property.
Set up a setter injection policy in your StructureMap initialization code (a Registry, Global ASAX, your Bootstrapper, etc -- wherever you set up your container).
Create your behavior to call StructureMap's "BuildUp()" on the output model to trigger the setter injection. The behavior will be an open type (i.e. on the end) so that it can support any kind of output model
Create a convention to wire up the behavior
Wire the convention into your FubuRegistry after the Routes section:
In your view, use the new settings object:
NOTE: I have committed this as a working sample in the FubuMVC.HelloWorld project in the Fubu source. See this commit: https://github.com/DarthFubuMVC/fubumvc/commit/2e7ea30391eac0053300ec0f6f63136503b16cca