ASP.NET IronPython

June 2009 - Posts

T4MVC 2.2 update: Routing, Forms, DI container, fixes
To get the latest build of T4MVC: Go to download page   This post is a continuation of various recent posts, most notably: A new and improved ASP.NET MVC T4 template The MVC T4 template is now up on CodePlex First, I’d like to thank all those who are using the MVC T4 template and sent me suggestions and bug reports.  Most issues have been addressed, and most suggestions have been integrated.  I’m up to the 8th CodePlex drop, and it’s only been a week! You can see the history of changes at the top of the .tt file. Frankly, when I started playing with this, I just thought it’d be a fun thing to spend the afternoon on.  Instead, I have probably spent close to half my time working on it in the last week.  And I do have other...
The MVC T4 template is now up on CodePlex, and it does change your code a bit
Short version : the MVC T4 template (now named T4MVC) is now available on CodePlex, as one of the downloads in the ASP.NET MVC v1.0 Source page .   Poll verdict: it’s ok for T4MVC to make small changes Yesterday, I posted asking how people felt about having the template modify their code in small ways.  Thanks to all those who commented!  The fact that Scott Hanselman blogged it certainly helped get traffic there :) The majority of people thought that it was fine as long as It’s just those small changes: make classes partial and action methods virtual. Don’t mess with ‘real’ code! It asks for permission, or at least tells you what it’s doing I started looking for a way to pop up a Yes/No dialog, but ended up going with a slightly...
Mind if my MVC T4 template changes your code a bit?
When working on my MVC T4 template , I was not able to use reflection to discover the Controllers and Actions, because the code that the template generates is itself in the same assembly as the controllers.  So that causes a bit of a chicken and egg problem. Instead, I had to get out of my element and learn something I was not familiar with: the Visual Studio File Code Model API.  It’s very different from using reflection, because instead of working at the assembly level, you work at the source file level. You have to first locate the source file you want to look into.  You can then ask for the namespaces that it contains, and the classes that they contain, and finally the various members in those classes.  To be honest,...
A new and improved ASP.NET MVC T4 template
A couple weeks ago, I blogged about using a Build provider and CodeDom to generate strongly typed MVC helpers at runtime. I followed up a few days later with another version that used T4 templates instead, making it easier to customize. And now I’m back with yet another post on this topic, but this time with a much simpler and improved approach! The big difference is that I’m now doing the generation at design time instead of runtime. As you will see, this has a lot of advantages. Drawbacks of the previous runtime approach Before we go and re-invent the wheel, let’s discuss what the issues with the runtime T4 approach were, and how this is solved by this new approach. Complex configuration : to enable the runtime template, you had to add a DLL...
A T4 based approach to creating ASP.NET MVC strongly typed helpers
Earlier this week, I wrote a post on using a BuildProvider to create ActionLink helpers .  That approach was using CodeDom to generate the code, and there was quite some user interest in it (and Phil blogged it , which helped!). Then yesterday, I wrote a post on the Pros and Cons of using CodeDom vs T4 templates for source code generation .  They are drastically different approaches, and while both have their strengths, T4 has definitely been getting more buzz lately. The logical follow-up to those two posts is a discussion on using T4 templates to generate MVC strongly typed helpers.  The general idea here is to use the existing ASP.NET extensibility points (BuildProvider and ControlBuilder), but rely on T4 templates to produce...
CodeDom vs T4: two approaches to Code Generation
There are many scenarios where the need to generate source code arises.  The MVC helpers I introduced in my last post is one such example.  Note that I am focusing on generating source code here, and not on scenarios where you may want to generate IL directly (which certainly do exist as well, but it’s a difference discussion). To perform the code generation, there are several different approaches that can be used.  The most simplistic one is to use a plain StringBuilder and write whatever code you want to it.  It’s rather primitive, but for simple scenarios, it just might be good enough. For more complex scenarios there are two widely different approaches that I will be discussing here: CodeDom and T4 templates.  Let...
A BuildProvider to simplify your ASP.NET MVC Action Links
Update : Please see this newer post for the latest and greatest MVC T4 template   One downside of using Html.ActionLink in your views is that it is late bound.  e.g. say you write something like this: <% = Html.ActionLink( "Home" , "Index" , "Home" ) %> The second parameter is the Action name, and the third is the Controller name.  Note how they are both specified as plain strings.  This means that if you rename either your Controller or Action, you will not catch the issue until you actually run your code and try to click on the link. Now let’s take the case where you Action takes parameters, e.g.: public ActionResult Test( int id, string name) { return View(); } Now your ActionLink calls...
More Posts