views:

99

answers:

1

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.

+2  A: 

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.

Mauricio Scheffer
Right, I was thinking of implementing my own and using the Helpers dictionary to help achieve that. But there's no existing piece that takes care of the registering, is there?
Jonathon Watney
I don't understand what you mean by "there's no existing piece that takes care of the registering"... I added another option to register helpers.
Mauricio Scheffer
I was wondering if there was some existing piece (a MonoRail facility, service, extension, what have you) that could already register helpers in an alternative fashion, that's all. I'll probably end up building my own. The IHelperDescriptorProvider looks promising. I take it if I replace the default one that I'll have to add FormHelper and friends through my implementation?
Jonathon Watney
No, the standard helpers are registered somewhere else. See the default implementation of IHelperDescriptorProvider for reference: http://bit.ly/emNl8 I don't know any other implementation.
Mauricio Scheffer