I have been tooling aorund with Elutian's CodeGenerator in the Contrib space of Castle's Monorail.
First, watch the screencast that explains how to set up the CodeGenerator. There is a typical Controller base class to use the generator provided. Basically, you need to just build the project from source and then configure your .csproj in your monorail/web project with the MSBuild target snippet provided. The 'SiteMap.generated.cs' will be, er, generated at build. One slight oddity I encountered is its interference with copying dependencies into my /web/bin folder during build. I'll probably just add a conditional to the build target or perhaps have it as part of a postbuild event to get around this and I am not familiar enough with MSBuild to work it out right now.
Once the generated file is in your project you of course need to 'Include In Project' the .cs file. Now you can write syntax such as 'Site.Home.Index().Redirect()' instead of string literals in your controllers. One thing it will do, too, is provide the following syntax when working with areas:
- Assume area structure /admin/useradmin, where 'UserAdminController' sits in 'Controllers/Admin' .
- Next assume we have a controller called 'AdminController' sitting in the 'Controllers' folder of your project.
- Syntax for accessing the UserAdmin actions will be Site.AdminArea.UserAdmin.Actions.Index().Redirect(); >>note the 'AdminArea' node
- Syntax for accessing the Admin actions will be Site.AdminController.Actions.Index().Redirect(); // note the 'AdminController' node
One thing not supported (yet?) is the ability for the generator to reflect on any base classes to any inherited actions to the current controller. For example, if HenController:ChickenController and the definition for Index() is in ChickenController (which is abstract), the Index actions doesn't appear in the generated code for HenController. The workaround for this is to simply delegate the actions within HenController to the underlying action and the generator picks up on it. I've never worked in any kind of generation stuff so this might be something I'll poke around at patching if it isn't by design.
Another thing to keep in mind is naming collisions with any controllers called 'Services'. The generator uses the field _services internally in the generated file and so any usage of this as a Controller name caused name collisions. It would be better to have less-common names as internal fields for these kinds of things I think.
I couldn't get the strong-typed Flash/PropertyBag stuff going that is out there since they ported the very cool DictionaryAdapterFactory over to the components project. I had a hard time tracking with all the docs I could find that were written prior to the move of the DictionaryAdapterFactory and I am needing to move on...
I found an example Elutian posted that is helpful as well.
Overall, the generator is useful. I'd like to see something that automates breadcrumbs and the like as well so am thinking how to do that.
References