Code generation and scaffolding

With all the respect that I have for the Castle projects and team members, their are two things I don’t like about the projects.
– Visual Studio Integration rather then a command line tool
– The scaffolding

So instead of complaining, here’s what I’ve done: The Generator, mouhaha! :
To compile and run:
1. Run svn co
2. Run nant in the base directory to compile
3. Run generate to get help

It’s a fully customizable code generator written in Boo and templates with ASP style syntax. I’ve made 4 generators: controller, model, generator and scaffold.

The scaffold generator is heavily inspired by RoR, it generates real code you can modify for the controller, the views, layouts, css and tests. The CRUD views will look similar to current MR scaffold with the difference that the code is live in you project so you can add a field, color, validation, change the workflow without copy pasting for the last controller you’ve done! Plus you already got some running tests! (just 2 simple for now)

To use it :
Edit the file Generators\ to fit your project structure
run bin\generate from your project root folder.

This is a work in progress so contributions or comments are welcome.

Oh and I almost forgot, a short video: Video



Filed under Generator

20 responses to “Code generation and scaffolding

  1. Anonymous

    This is cool. Do you have any an instruction, doc or C# version of the generator available. I don’t know BOO.

  2. MAC

    Not any doc at the time but I think the generators code is pretty self explanatory. Plus you can use the generator code generator to create a new generator template to start with. If you have any questions I’ll be please to answer them.

  3. Two things would make this much more useful:

    * allow configuration of the area which the controllers/view are in (so allow e.g. /administration/product/edit.rails?id=1

    * allow configuration of the file extension – i use .rails and not .aspx

  4. MAC


    The source is at:

    run nant at the base directory to compile.

    Thanks for the feedback

  5. That’s excellent, thank you. I’ve checked it out from SVN, it’s not immediately obvious what you’ve changed to support Areas… Can you explain how this would work?

  6. Hmm, still doesn’t work, for example in the scaffolded lists I get:

    $HtmlHelper.LinkTo(“Add a new Product”, “Products”, “New”)

    Whereas I think it should be:

    $HtmlHelper.LinkTo(“Add a new Product”, “administration/products”, “New”)

    And I don’t see a way of configuring it to do this.

  7. MAC

    You’re right… I’ll try to fix this ASAP. But you can easely modify every template you want. They are located in GeneratorsScaffoldTemplates, the syntaxe is asp like.

  8. Yeah, I could hard-code the Area into the scaffolding templates. But a variable for the Area would be the nicest way so that’s why I brought it up 😉

  9. MAC

    Fixed in rev 60.
    (no need to recompile, just update the Generators directory)

    When you generate a new scaffold the controller and tests are placed in the namespace of the area, ex.: MyApp.Controllers.Admin for the area Admin. Links and views locations have been placed. Everything should work fine now!

    Thanks for the interest!!

  10. That is absolutely brilliant. Thank you very much!

  11. Anonymous

    I can’t checkout nproject!
    Is it still up?

  12. MAC

    I think sourceforge’s svn server is down for a moment, try again in a couple of hours.

  13. henri

    Hi MAC,

    Are you using Monorail in production?

  14. MAC

    I use MonoRail, ActiveRecord, Generator and Migrator at work and on my personnal project (NProject).

    If that’s what you mean by production, then yes!

  15. Henri

    I guess I mean a live site, on the internet or an intranet.

    I am hesitant to use a beta product, but I can’t resist. I am coming from Java and more recently Ruby to ASP.NET, and it seems that the default Mircosoft way (forms, datasets, etc) is not layered or object-oriented.

    If I don’t use something like Monorial I would need to create a framework myself. That would not be productive.

    In any case, any advice is appreciated.


  16. MAC

    Demo version of NProject is currently hosted on a live server But it’s down for now : (’cause of dependencies related to NSvn a subversion binding for .NET). But it worked perfect before. I’ll fix this ASAP so check back later.

    MonoRail surely has some weakness, but beeing an open source project I know that if it’s not going the way I want, I always have the option to fork and start my own version. That’s alot better then starting a framework from scratch! That’s the power of open source!

  17. MAC

    NProject is now working!!!

    Check my post for infos.

  18. Anonymous

    Hi Marc,

    First my compliments for your work! Very impressive..

    BUT…. could it be possible that you’re generator could generate a application skeleton? Something like TreeSurgeon does?

    Thanks in advance

  19. MAC

    I’m working on this one Peter!

    Thanks for the suggestion

  20. Anonymous

    Are you interested in donating the code to the Castle Project? We would probably need to convert to C# as we can’t force people to have boo (or any non-standard tool)

    Thing about it.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s