Headspring’s MVC Boot Camp now covers MVC 2 – April 21, 22, 23

Sign up here for Headspring popular boot camp class.  The April boot camp cover ASP.NET MVC (version 1 and 2).  Jimmy Bogard, principal consultant and author, is the trainer for this class, and Jeffrey Palermo (me) is the assistant trainer.  If you employer sends 3 or more there is a discount, so be sure to ask about that.

This is a very hands-on class, hence the name “boot camp”.  Your brain will be fatigued at the end of every day.  The material comes directly from how Headspring uses ASP.NET MVC while delivering client projects.  No theory here – only practice.

http://www.headspringsystems.com/services/agile-training/mvc-training/, or call (877) 459-2260.

More info below:

Developers can easily leverage the Model-View-Controller pattern in ASP.NET applications. Pulling logic away from the UI and the views has been difficult within custom application development for a long time. The Model-View-Presenter pattern helps a little bit, but the fact that the view has to delegate to the presenter makes the UI pattern difficult to work with.

Headspring has been using ASP.NET MVC since the original prototype and has presented on the topic at local conferences as well as Microsoft TechEd. Headspring employees are responsible for a book on ASP.NET MVC, as well as MVC Contrib, CodeCampServer, and several community Solution Templates. This boot camp offers the opportunity to share the experience using the ASP.NET MVC Framework on real-world systems. The class is run in our "boot camp" style where we move quickly and deeply through the topics at hand. The class is three days, and a lot of information is packed into those three days. Instead of written labs and individual exercises, the class will work together as a simulated development team and extend an existing application using the techniques learned. The students will work together and learn from each other as well as the instructor.

Topics are separated by day based on student experience and class speed and will be approached using C# as the scripting language of choice.

Instructors for the ASP.NET MVC Boot Camp™ are Jeffrey Palermo and Jimmy Bogard, two of the authors of ASP.NET MVC in Action.

Topics:

  • History/Overview of ASP.NET MVC
  • Separated solution structure
  • Basic & customized routes
  • Customized route handlers
  • Controller selection
  • customized controller factories
  • Controller & Action patterns & anti-patterns
  • Read-only views
  • Data-entry views
  • Presentation Model
  • Advanced ActionResults
  • Action filters and ActionFilterAttribute
  • Server-side validation
  • JQuery integration
  • Deployment and installation
  • Advanced View Helpers
  • AJAX with ASP.NET MVC
  • T4 Templating
  • Connecting with data access, messaging, etc.

Onsite Training Available:

For companies that want to maximize their programming teams, Headspring Systems can create training courses customized to meet your needs. For more contact us at training@headspringsystems.com

ASP.NET MVC in Action podcast with Deep-Fried Bytes crew

Thanks to Keith and Woody for having us on their podcast.  It was a lot of fun.  The podcast is now published.  Here are the details.

Episode 48: Web Development with ASP.NET MVC In Action Authors

About This Episode

In this episode Keith and Woody caught up with the team that wrote the book ASP.NET MVC In Action: Jeffrey Palermo, Ben Scheirman and Jimmy Bogard. The guys discussed the book, what drives their passion around ASP.NET MVC and what is in store for this huge change in ASP.NET development.

Attend free workshop on 3/16: Architecture Analysis Patterns

On Tuesday, 3/16/2010, Headspring is offering another free monthly workshop.  This month, I am leading the workshop, and the topic is:

Architecture Analysis Patterns: How to reason about the structure of an application

Layering, a fundamental concept of software architecture: Layer helps to separate dependencies and to decouple concerns. Most of the industry does layering in name only. It's lip service. In 23 slides and accompanying commentary, we will explore the fundamental concept of separating layers to absolutely isolate dependencies.

Tuesday, March 16, 2010
2:00 PM to 4:00 PM

Microsoft hosts Headspring at:
Microsoft Technology Center
9606 N Mo Pac Expy
Austin, TX 78759
(map)

Supercharging ASP.NET MVC with MvcContrib (article)

CoDE Magazine has published a new article from me on MvcContrib.  Here is an excerpt:

Hot on the heels of the groundbreaking release of ASP.NET MVC CTP 1 in December of 2007, an open source project called MvcContrib came to life. MvcContrib has enjoyed tens of thousands of downloads since it started in December of 2007. In this article, I will explain MvcContrib; it’s major components, how to use it, and how to get involved in its continued development.

MvcContrib from 30,000 Feet

MvcContrib is a .NET 3.5 SP1 library that provides extensions for use with Microsoft’s ASP.NET MVC Framework. MvcContrib does not provide replacements for parts of ASP.NET MVC.

 

Click here for the full CoDe Magazine article.

I am speaking at the Lubbock .Net User Group on March 29th

If you live in the area, or if you are a student at Texas Tech University, come on out to the Lubbock .Net Users Group.  More details to follow.

http://www.ldnug.net/

Headspring continues to hire: we will train contract-to-hire positions

Refer to position details: http://www.headspringsystems.com/careers/senior-software-engineer/

Headspring is always looking for good people, and we have continued to expand throughout the downturn in the economy.  Over 2009, I increased our development staff 13%, and already in 2010, it has increased 11% just in the first two months.  We are continuing to grow, and it doesn’t look like it is slowing down.

There are two model which work very well:

  1. Contract-to-hire:  This is when a programmer very confident in his capabilities works on a contractor basis for a project while we both decide if it is a long-term fit.  Some individuals decide they like contracting and continue in that model.
  2. Full-time employment w/ 90-day trial:  This is when a programmer definitely wants full-time work including top-notch benefits.  At about 90 days, we reevaluate the fit.  We or the employee can then decide to enter into a more permanent employment agreement.

I am currently looking for programmer who fit into either category.  Please email seniorsoftwareengineers@headspringsystems.com if you are interested.  Refer to http://www.headspringsystems.com/careers/senior-software-engineer/ for the items to include in the email.  Don’t let the email address fool you.  If you are aspiring to improve yourself but are not at the senior level, we want to speak with you as well.  Smart people are hard to find.  I can train you up, but I can’t make you smarter.  You have to bring that to the table by yourself.

Most companies who hire contract-to-hire won’t train them.  We are different.  Anyone who does any work for us represents us.  I believe that it is critical to our reputation that we equip our people with the tools and knowledge to succeed in any project.  We are very leading-edge, and we use the best tools the industry has available.  This is different from being “bleeding-edge”.  I do not believe in bleeding.  We will adopt those items which have passed the bleeding stage and have proven their value.

It takes several weeks to make it through our screening process, so please understand the lead time.  Identifying the right people is something I take very serious.

Video of C4MVC talk on MvcContrib Portable Areas

Recently, I gave a presentation to the C4MVC virtual user group focus on ASP.NET MVC, and headed up by Eric Hexter.  You can see the meeting info here.  I introduced and walked through a Portable Areas sample.  the purpose of MvcContrib Portable Areas is to provide a component model for ASP.NET MVC.  It’s not perfect, but it is a very powerful model.  Our hope is that, along with MvcContrib participating in the CodePlex Foundation, Microsoft will be able to take some of the code, or perhaps just the idea, and productize it into the much-needed component model for ASP.NET MVC.

Headspring Agile Boot Camp, March 24-26 – sign up now – Austin, TX

Started in January of 2008, Headspring’s Agile Boot Camp series of trainer has received many positive reviews both from local Austin developers to folks traveling from other parts of the country.  Go to Headspring.com, and sign up for the next class now.

This training encompasses...

Part I Agile Boot Camp™ Topics:

  • object oriented programming
  • SOLID principles
  • design patterns
  • dependency injection
  • team design on whiteboard
  • IDE tools and quickly navigating a codebase
  • Test-Driven Development
  • mocking
  • pair programming
  • refactoring
  • pain driven development
  • Domain Driven-Design
  • ORM
  • contributing to open source projects
  • harnessing the community for extreme growth and continuous learning
  • foundations of Agile
  • Continuous Integration:
    • the "check-in dance" to ensure that code to be committed to a repository does not conflict with existing code or unit tests
    • to make code repositories automatically integrate with build scripts to build the most current source to staging servers
    • to make code repositories automatically integrate with build scripts to alert teams if any developer commits code that breaks any of the project's unit tests (thus keeping the source code free of bugs)
    • to write deployment scripts to make separate databases from the project's schema at individual developer/pair-programming workstations and well as production and staging servers
    • to write deployment scripts to roll out database changes as they occur at individual developer/pair-programming workstations and well as production and staging servers

What will I need to do to prepare for the training?

You've learned the .NET Framework - now learn the principles and tools to use it effectively. This intermediate curriculum will lead developers to work-changing techniques and create momentum towards continuous improvement in an ever-changing field. With a focus on object orientation and software engineering practices refined in real projects, students will discover principles and patterns to manage software complexity. By the end of the course students will have eliminated a reliance on leaky-abstraction APIs by

  • understanding software design concepts and principles
  • understanding and practicing test-driven development
  • practicing working in an effective team
  • implementing designs using object oriented techniques and design patterns
  • understanding object-relational mapping
  • driving future growth through exposure to advanced topics

Day 1

getting started

  • lab 1: check out the project and run a unit test
  • module: Intro
  • module: TDD basics
  • lab 2: writing your first failing unit test
  • lab 3: writing the code that makes it pass
  • demo: working with resharper

LUNCH (provided)

object oriented programming

  • module: SOLID
  • lab 4: interfaces, facade
  • lab 5a: strategy pattern
  • lab 5b: command pattern
  • extra curricular lab: playing with structuremap

Day 2

team design & advanced tdd

  • quick mini-lab involving structuremap
  • module: dependency injection / ioc
  • lab6: configuring structuremap
  • demo: testing with mock objects
  • lab7: rhino mocks
  • team design on whiteboard

LUNCH (provided)

refactoring & pair programming

  • lab8: more tests, enumeration base class, specification pattern, .NET 3.5 feature in the code
  • module: refactoring
  • demo: refactoring legacy code
  • lab 9: pair tasks involving refactoring
  • extra curricular: student-driven discussion and demo

Day 3

morning session

  • lab 10: "refactor this" challenge
  • module: DDD basics, terminology
  • lab 11: repositories, using provided nhibernate stuff (HSB, DTB, etc.), specification pattern
  • module: foundations of Agile

LUNCH (provided)

conclusion

  • module: nhibernate
  • demo: querying nhibernate
  • lab 12: downloading source, creating patch for open source project
  • student-driven discussion, demos

A glimpse at Tarantino database management:

Training located in Austin, Texas (8:30 a.m. to 5:30 p.m.)
Although it is unlikely, class dates are subject to change. We encourage you to obtain transferable airline/hotel reservations in the event that this should occur.

Call Headspring to Enroll: (877) 459-2260

Check out Mercurial version control with my CodePlex repository

Mercurial SCM (Hg) is a Distributed Version Control System (DVSC).  More importantly, your code doesn’t know or care how it is being versioned.  In other words, None of your VS solution or project files will be modified with a pointer to source control, and no *.scc files will be added in your code.

Interesting enough, Martin Fowler currently recommends Mercurial above the others at this point in time.

To get started, you will want to install the Mercurial Visual Studio 2008 SCC provider (for commits) as well as TortoiseHg, which is the tool you will use the most.

Check out my repository at http://palermo.codeplex.com with the getting started guide.  If you already know Hg, the Hq repo can be cloned at https://hg01.codeplex.com/palermo.

For those who are new to Tortoise, Here is how I would go about getting the source:

image

I do have TortoiseSVN, TortoiseGit, and TortoiseHg installed.  The experience is very similar among the tree, and they do not conflict with each other.

Add post-backs to MVC –or- add front controller to Web Forms

You can download the code for this post at my CodePlex repository: http://palermo.codeplex.com/

Lots of programmers I talk to are managing software assets written in ASP.NET.  These applications have been in production for years, and they work.  The problem that is pervasive among all of them is that the Page_Load method is much too large.  Model-View-Presenter is fatally flawed as a pattern because the view obtains control before the presenter does.  This wrong ordering is an unrecoverable error in the workability of the pattern.  I have spent a number of years attempting to implement the MVP pattern well before I came to this conclusion.

This post contains a short example that inserts a controller in the request pipeline before the Web Form.  This allows large and bloated Page_Load methods to offload a bit of logic to a controller that executes in front of the Web Form.  Interestingly enough, this same technique allows an ASP.NET MVC page to leverage post-backs and server side controls.

Here is the solution view:

image

Default.aspx.controller.cs is the controller that executes ahead of Default.aspx.  The Visual Studio tooling doesn’t know to nest this file like I would like it.

Here is the page run the first time:

image

And here is the page after 3 clicks on the button that is an <asp:Button/>

image

Our page looks like the following:

<%@ Page Language="C#" AutoEventWireup="true" 
CodeBehind="Default.aspx.cs" 
Inherits="MvcApplication1.Controllers.Default" %>
<%@ Import Namespace="MvcApplication1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <%var cust = (Customer) ViewData["model"]; %>
        
        <h1>Web Form with front controller</h1>
        Customer #: <%=cust.Id %><br />
        Name: <%=cust.Name %><br />
        Is Preferred: <%=cust.IsPreferred %>
        
        <asp:Button Text="Do a postback" runat="server" ID="btn" 
        onclick="btn_Click" />
    </div>
    </form>
</body>
</html>

Here is the code-behind:

using System;
 
namespace MvcApplication1.Controllers
{
    public partial class Default : ViewDataPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
 
        protected void btn_Click(object sender, EventArgs e)
        {
            btn.Text += " - " + DateTime.Now.ToString("hh:mm:ss");
        }
    }
}

Now, we can see that we are retrieving the Customer from ViewData.  But wait, Web Forms don’t have view data.  That’s correct.  That’s why I’ve made ViewDataPage an IViewDataContainer:

using System.Web.Mvc;
using System.Web.UI;
 
namespace MvcApplication1
{
    public class ViewDataPage : Page, IViewDataContainer
    {
        public ViewDataDictionary ViewData { get; set; }
    }
}

Now, here is the route that we are using:

using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
 
namespace MvcApplication1
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801
 
    public class MvcApplication : HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
 
            routes.MapRoute(
                "Default", // Route name
                "{controller}", // URL with parameters
                new {controller = "Default"}
                // Parameter defaults
                );
        }
 
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
 
            RegisterRoutes(RouteTable.Routes);
        }
    }
}

Now, what does the front controller look like?

using System.Web.Compilation;
using System.Web.Mvc;
using System.Web.Routing;
 
namespace MvcApplication1.Controllers
{
    public class DefaultController : Controller
    {
        protected override void Execute(RequestContext requestContext)
        {
            var customer = new Customer
                               {
                                   Id = 2,
                                   Name = "Jeffrey Palermo",
                                   IsPreferred = true
                               };
 
            ViewData.Add("model", customer);
            string controllerName =
                requestContext.RouteData.GetRequiredString("controller");
            string pagePath = string.Format("~/Controllers/{0}.aspx", 
                controllerName);
            var page = (ViewDataPage) BuildManager
                  .CreateInstanceFromVirtualPath(
                  pagePath , typeof (ViewDataPage));
            page.ViewData = ViewData;
            page.ProcessRequest(System.Web.HttpContext.Current);
        }
    }
}

Notice that I overrode the Execute method.  In this case, there is no need for the concept of an action.  We merely have an object that executes before the Web Form.  Then the controller builds the Web Form and asks it to process the request.

Half of this method could easily be factored into another class, but it works very simply.   I did not have to jump through any hoops.  I hammered out this code in about 10 minutes.

If your Page_Load methods are getting too long, consider putting a front controller in front of the page.