I moved to Austin, TX 4 months ago, but just finally made it out to the Austin .NET User Group meeting this month. Jeffrey Palermo was the speaker, talking about isolation of concerns, testability, and ASP.NET MVC. All kinds of terms that I could never repeat at home without being looked at like I'm speaking in tongues. I figured it would be an interesting talk, but afterwards, I felt a bit like I had been jolted out of some sort of sleep.
A parody of a parody from Rob Conery seems to fit:
Jeffrey: Let me tell you why you're here. You're here because you know something. What you know you can't explain, but you feel it. Your pages are breaking at the seems. You spend hours tracking down why an event didn't fire. There's certainly a better way. You don't know what it is, but it's there, like a splinter in your mind, driving you mad. It is this feeling that has brought you to me. Do you know what I'm talking about?"
Me (and much of the audience): MVC?
Jeffrey: Do you want to know what it is?
Me: Swallows and nods (do we have to learn everything from the beginning now?)
Jeffrey: It's all about separation of concerns...
My apologies for poor parody's - I promise I'll keep my day job. But while I'd already seen or at least been exposed to most of the topics, the way it was presented this time and perhaps the project I'm working on now just made it all click. I felt a bit like Neo seeing for the first time.
A little background... I'm currently working on a project to convert a .NET WinForms app to the web. I have quite a bit of .NET experience, having written a CMS tool, sales lead tool, and public website for my previous employer. The public website was Java Struts (MVC) while the internal applications were all ASP.NET. At the time, I much preferred the simplicity of the ASP.NET page model. I thought Microsoft just got it right. Struts is so complicated, while ASP.NET made things simple. Why do I have to edit a controller, 2 xml files, and 1 or more jsp's just to create a new page. I loved ASP.NET...
New job, new projects, and a new expectation for the web, and now the ASP.NET abstraction is starting to not just leak, but poor. A video on Google GWT really summarized how I feel:
- Experiment with "a bit of script"
- Everybody loves it! More!
- We're an AJAX shop???
- Attempt to port to something other than Internet Explorer...
But luckily, ASP.NET made it so easy! UpdatePanel to the rescue.
So how does this relate to MVC? Or separation of concerns? Here's how I'm hoping... but I'm just about to start on this journey to see if there's anything down the rabbit hole.
What I envision:
- Start refactoring code to decouple. Use dependency injection to assist with this.
- Already added Unity container to the project and have it in place for 1 ASPX page. I thought about one of the other popular dependency containers, but sometimes it's easier to get buy-in on a "Microsoft approved" way to do things when working at a Microsoft shop, we can always switch this out later if needed.
- Find a good sample page in our current application to refactor to MVC, adding decent coverage from unit testing. Keep view extremely simple.
- Question: Is it possible to have controllers at two levels - both server-side in C# and client-side JavaScript? Would you want that? Or should control firmly rest on either the server or the client. We currently have events being handled in a mix of client and server side, which can make it extremely complex to follow an execution path.
- Get buy-in from other developers / management that this is a good way to move forward for the rest of the project.
- Start adding a series of additional JavaScript unit tests to test much of our JavaScript AJAX code ( this could precede 2 and 3)
- Make the above a habit for new work, and try to retrofit to as much of the stuff we've already done as practical.
My team has done a lot of things right - we have all of our SQL in DAL classes far away from the presentation layer. We have continuous integration on development branch, one click build on release branch, a good branching structure, and use TFS religiously for work item tracking. We keep all of our development goals prioritized so everybody knows the most important thing to be working on, and has visibility to what's coming up. We've not yet invested the time to have a really testable design.