是否有其他方法可以在 MonoRail 中向控制器注册助手?

发布于 2024-07-27 13:57:08 字数 394 浏览 3 评论 0原文

在 MonoRail 控制器中,可以使用 Helper 属性进行装饰使助手在视图中可用。 是否有另一种方法可以通过配置文件或依赖项注入向控制器注册助手? 我热衷于避免创建一个基本控制器只是为了提供帮助程序并向控制器层次结构添加另一个控制器。

In MonoRail controllers can be adorned with the Helper attribute to make helpers available in views. Is there another way to register helpers, perhaps via configuration file or dependency injection, with controllers? I'm keen on avoiding creating a base controller just for the purposes of providing helpers and adding yet another controller to the controller hierarchy.

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

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

发布评论

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

评论(1

没企图 2024-08-03 13:57:08

IControllerContext 有一个 Helpers 字典。 所有控制器都通过 ControllerContext 属性公开 IControllerContext。

另一种选择是实现 IHelperDescriptorProvider 来替换默认的(从 [Helper] 属性读取帮助器描述符)。 您的实现可以从配置或您想要的任何内容中读取帮助程序配置。

IControllerContext has a Helpers dictionary. All controllers expose IControllerContext via the ControllerContext property.

Another option is to implement an IHelperDescriptorProvider to replace the default one (which reads helper descriptors from [Helper] attributes). Your implementation could read helper configurations from a config or whatever you want.

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