Tagged: Coding, Database, DotNet, ASP.Net
Professional ASP.Net MVC3 by Jon Galloway, Phil Haack, Brad Wilson and K.Scott Allen
With only a bad taste in my mouth from a short time on MVC1 and I’d-rather-code-than-blackbox toe-dips into Entity Framework over the years, I went to all of the LA DotNet Saturday MVC deep dives presented by Scott Mitchell. I figured that maybe seeing someone with the faith and with release experience might turn my crusty old bent. It did. Mitchell got me pondering whether it was time to actually trust the MVC-EF product on a real application three versions before the blessing of “Version 6” release.
So I went looking for a guidebook and one of the first MVC3-EF4.1 releases with “Professional” in the title was this one from WROX; it’s light (weight-wise) and at less than an inch thick it looked like a pamphlet on the shelf next to the C#4 in A Nutshell phonebook, but the chapter names appeared to cover the gamut that I’d need for starting something simple and most of the four authors are well known rock stars so I made the investment.
Well… I dunno, now that I’m committed to a project it’s clear that life hasn’t changed. There’s a lot of coding and workarounds required to get a moderate MVC3-EF app out the door safely and that’s fine, that’s code. The point of this review isn’t with the realities of the product, it’s that this book says “Professional” but doesn’t cover those workarounds or tend to mention some of the basic ‘Typically Annoying’ tidbits of the product. It’s all happy path and rainbows and unicorns.
The first chapter is a typical “Getting Started”, with a historical overview and description of how some ASP.Net developers were tired of “the lie” of the event-driven metaphor and how MVC is a huge boon to the lovers of complete separation of layers (you have to wait for the first page of chapter two to get the admission that the author's requirement of separation of Ms, Vs and Cs is more philosophical than physical... and this is a MAJOR shortcoming of the book, just the first few chapters of Dependency Injection in .Net from Manning Press proves that separation is not only possible in MS MVC but mandatory for a "Professional" project, that book shows clearly as wrong action what this one pushes as "Professional".).
I laughed out loud in the section of bullet points for the things version 3 brings to the table (there were a whopping six of them) because every one had an exclamation point and the last one had four (“!!!!”). Spoiler alert: that super fantastic feature that made the author squeal with delight? “Now With NuGet!!!!” That bullet is foreshadowing.
Chapter Two is titled “Controllers” and don’t ask why they started with the last letter of the product name, they tell you right up that it was a chicken and egg problem no matter what they chose. No matter, it gives the definition of what a Controller is as compared to the WebForm event-driven metaphor and covers the basics.
A small thing that jumped out of this chapter was a half page sidebar about why Cassini uses random port numbers. It just seemed weird at this point in ASP.Net’s ten years, and that grey box kept coming to mind all through the book when the authors would say that the reason they weren’t going to show some example or another was ‘because this book is targeted at Professionals we don’t think we have to go into detail on [fill in your unclear issue here].’ Great guys, but thanks so much for the cutting edge info on that new Cassini thingie ;-).
Chapter Three is Views, basically. As an MVC noob, I thought that at least a tiny bit of time in this chapter was going to be spent on some small background on tweaking the UI, at least enough to change the default fat-tabbed blue layout or to get rid of the tab for the default anyone-can-sign-up LogIn system. Instead right up front we are told: “we won’t show you how to make a pretty view, because our own aesthetic skills are lacking”… and they mean it, there is not a single mention of any ties to CSS or even of the folder areas related to look and feel of an MVC3 application. How much would it have hurt to put one more author on the payroll, for just a five page chapter on what’s where and how to start making an app look like your own. I mean, when all is said and done, MVC is fundamentally a GUI platform, isn’t it? Maybe UI information was left out to save trees, if so then it would have been an even swap to use that Cassini random port space for a url or two here relating to modifying the looks and feels.
Aside from that, Views gives a lot of comparisons between WebForms and MVC (always with MVC being the winner) so I was looking forward to finally seeing a discussion of how – or IF - partial views relate to ASCX/User Controls. User Controls and componentizing is so near the heart of WebForms that showing how MVC3 gets the same result or telling why it doesn’t was expected, but alas. Partial Views are mentioned as being an option on the Add View dialog with a definition straight from MSDN that assumes you already knew exactly what they were and how they relate to Layouts… but remember that they never talk about Layouts in the book so it’s less than helpful.
Views does have some good moments, there’s lots of talk of RAZOR, nice descriptions and several side by side examples of the new syntax versus ASP.Net styles. A few of the example snippets made me think “that’s an interesting bit of code, why would I want to use that?” but these were all just comparisons with no context. Next…
Chapter Four: Models. Here is where we are told that you can use anything for your models, EF is not required and databases are not required “you can use a comma-delimited files or web services using the full complement of WS-* protocols if you want!” Exciting!
Too bad the only Model basing topic covered in this chapter is Entity Framework Code First. Code First is really neat but in a “Professional” MVC3 chapter on Models you’d think that you’d get maybe an example of Database First or (pushing it here) Model First... or tweaking anywhere in the data layers for efficiency. Nope. Code First right clicking is the brunt and you get it really fast (so fast that they forget to mention that anyone who thinks enums are useful in object models is going to be sadly surprised by the database columns – and Views – that are created). There is a sidebar to tell us all that you can get around any autocreation issues or cranky DBAs by changing the mapping between the models and the database and it gives an MSDN url for that.
The Models chapter moves on to describe what Scoffolding is and how if you don’t like the defaults you can just hit NuGet and download loads of other scaffolding libraries (Why? Any common reasons? No.) or you can handcraft your own (Can I get a fast basic example? No.). To be fair, there is an “Advanced Scoffolding” section is the book’s last chapter… it tells you the blog urls you can use to find practical information ;-(.
A nice teaser was at the end of the chapter four, a heads up about the dangers of the “aggressive search behavior” of Model Binding specifically related to over-posting. It got me pumped for what was ahead in the security sections and, honestly, I got a lot of juice out of Chapter 7 but, like so much of the book, that too was a lot of buildup then a quick wrap that told you to use NuGet (“!!!!”) to get a library that takes care of every little problem you could ever come up.
I think you’re getting the idea by now. The book has a lot of great chapter titles and each chapter does generally stay related to the title. It’s just that most every chapter reads like it is starting off deep then gives you a url or advises you to poke your way around NuGet (“!!!!”).
Hey, I know what this book is; it’s a bunch of conference sessions transcribed and printed out. The authors did their shows and were really rolling strong but then they got the word that they only had two minutes left so they had to bail. That’s what the chapters feel like.
Yes, you can quickly find tutorials showing Code First, Model First and Database First MVC demos online (Julia Lerman has excellent ones doing them all side by side quick as a bunny). You can find everything online. But there are still valid reasons that the book could have spent a few extra pages doing the same thing: 1) “Professional” is in the title, 2) it’s a book. People are paying $45.99 retail so that when they are in a non-wired book-reading environment they can get the full story. I think folks put those two points together and they deserve to get more than just a single way of doing things with no warnings of gotchas and a lot of urls to use “for the details”.
I am new to MVC3-EF so my issue isn’t author envy. I know that I’m not smarter than any of the writers by any means. I just felt like if the title had been “An Overview…” or “An Introduction To MVC3 for ASP.Net Intermediates” it would have fit better.
I almost tore up this review after writing the last paragraph because perhaps they were trying to warn folks that it was an Overview with the blurb on the back cover, but fact is they imply that it is going to be the end-all reference to this release. I can’t give them the benefit of the doubt when I see the bullet: “Uncovers tips for making use of membership, authorization and security features” and I know that while Chapter Seven has a lot of starting point tidbits and security vectors to watch out for… the extent of information on using the Membership And Role Providers in MVC is limited to three bullets telling you “You can use your existing code skills based on working with the ASP.Net Membership system”, “You can extend the default AccountController” and “You can leverage the provider system to create your own Membership, Role and Profile providers” but then stops without any words on How you can do any of these things. Not even a url.
To wrap: There is a short chapter on TDD, one on Patterns and DI and two short “advanced topics” chapters featuring both quick context-free examples that made me ask “but why would I need that?” and some actual code stuff. One of the best sections in the whole book was the very last topic where we finally see asynchronous controller code (yay!), ending with a mention that while you can get into this yourself, you should just download a library from NuGet that does it for you.
My gosh, how could I have forgotten the longest chapter in the book? Chapter 10 is every single possible thing you could ever want to know about the “package management system for .Net and Visual Studio that lessens the difficulty of adding external libraries to your application.” NuGet, in complete and absolute loving detail. Four exclamation points for NuGet ;-).
I hated the book right? Actually, I liked it a lot. It’s like the “Hope And Change” platform; when I didn’t know any of the details it all sounded great and that got me behind it. I think it would have been more satisfying in the end if it was $29 instead of $45.99 and if it had mentioned even once in all the Code First stuff that enums still aren’t available in an official Entity Framework release (or at least one way to work around the ongoing limitation) but it did the job for Microsoft, it got me excited about taking the plunge.
This book is not going to be anyone’s go-to desk reference, but when a coder hits those inevitable times when they hate coding in the MVC product, pulling this book out for a refresh of the original naive excitement might help. That benefit is worth something… maybe fifteen bucks used.
Now with NuGet!!!!... just grab a library because developers are just too darned stupid to get into code. I dunno WROX, this attitude (and the overwhelming MVC3 EF-ONLY blackbox approach that the book and MS are more-than-gently pushing) brings back the days of forms plastered with MicroHelp VBXes. Ah well, at least we all glue the libraries together with semicolons now ;-).