是否有其他方法可以在 MonoRail 中向控制器注册助手?
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.