What ASP.NET MVC Can Learn From Ruby on Rails

Simon Torkumine, a Ruby on Rails developer, recently blogged about how the ASP.NET MVC framework compares to Ruby on Rails. While there are some parts of his post that I don't necessarily agree with (e.g. the anemic community, C# being too verbose), one point he brought up rang true to me:

.NET MVC is actually .NET VC. It is an attempt to replicate the Actionpack components of Rails. There is nothing included aside from a folder labeled “Models” to help you with your persistence later and domain modeling. As others have mentioned, there are other ORM tools out there, but bear in mind these are targeted at traditional ASP.NET development and are not integrated into the framework as in other MVC’s. This means that you’ll be writing your own validation and form handling code for starters.

I couldn't agree more. The biggest pain point in my development experience with the ASP.NET MVC framework has been its incredibly lax approach to the "M" in "MVC". Whereas the views and controllers are pretty much hashed out, developers are essentially thrown into the deep end when it comes to the model. That means that persistence and validation is completely up to us, which is great for experienced developers who have very opinionated views on what best to insert here but extremely terrifying when for developers approaching the framework for the very first time.

This may be a matter of opinion here, but for me web application frameworks are expected to come with all the necessities to get a basic site up and running. This is not so when it comes to the ASP.NET MVC framework. At first it appeared that Linq 2 Sql would be the clear-cut answer to the persistence question. After all, Linq 2 Sql was developed by Microsoft and was used in almost every single Microsoft blogger's posts on ASP.NET MVC. But then something happened. Microsoft announced that it would no longer be supporting Linq 2 Sql and ever since then the community has been a flock without a sheppard.

Microsoft's suggested replacement, the Entity Framework, is so actively despised by the community that there was a petition against it. To date, I have yet to see a single example of integrating the Entity Framework into an ASP.NET MVC application. NHibernate has a decent following, but it's not exactly user friendly or easy to set up. Subsonic, the obvious alternative to Linq 2 Sql doesn't appear to have garnered too much support.

Validation has also gone by the wayside because of this as it is tends to be tied in with the persistence layer. Scott Guthrie's initial post on validation in the ASP.NET MVC framework revolved around handling Linq 2 Sql's "OnValidate" event when saving off entities to the database. Now that Linq 2 Sql is essentially out of the picture, we're left with either writing our own or going with one of the many newly created OSS solutions like xVal.

There is a significant difference between being allowed to go outside the box and being forced to. The "rails way or the highway" approach that Ruby on Rails takes is great for beginners, but not so great when you want to go outside of the box. ASP.NET MVC's complete lack of guidance when it comes to models has the opposite problem in that beginners don't know what to do, but are free to explore whatever options they want. This may prove to be a big problem for the adoption rate of ASP.NET MVC now that it's advancing past the point of early adopters who are willing to put up with the growing pains.

To be clear here: I know that there are several valid solutions for how to handle validation and persistence in ASP.NET MVC, and it's great that each of them is available to us. The problem is that you have to actively hunt these solutions down instead of having one of them baked into the framework. It's great that ASP.NET MVC is so extensible that you can essentially plug in whatever you want, but at some point some basic guidance is called for. A blank slate is intimidating and not very user friendly

In the end, it seems like there should be a middle ground between the Ruby on Rails approach and the ASP.NET MVC approach. Perhaps the project template could ask the user if they wanted to link this application up to an existing database or create a new one?  If they did, it could generate the model (even if it were empty) using Linq 2 Sql and throw in Scott Guthrie's validation code in there as well?  That would provide users with a starting point at least that could be easily ignored or stripped out if so desired.

What are your thoughts? I want as much as anyone else to see ASP.NET MVC become successful — and in my opinion it could be — and it would be a shame to see if struggle in the wild because it didn't take a few extra steps to cater to the beginner audience.

 

Kevin Pang

Kevin is a software engineer at Google whose programming interests revolve around web development, software architecture, and design. When he's not writing software, he enjoys watching Jeopardy!, playing Magic the Gathering, and wandering around Disneyland.

 

27 thoughts on “What ASP.NET MVC Can Learn From Ruby on Rails

  1. Why don’t you use one of the opensource frameworks?
    A major benefit of Asp.Net MVC is that is does only one thing: the web part of an application. It is not a complete application framework like Ruby on Rails.
    The idea is, that different applications need different tools and frameworks and programmers have different preferences. There is an active .Net opensource community and lots of frameworks are created. You will need a build engine, an ioc container, a mocking framework, a testing framework, an orm, a validation framework, a logging framework, and maybe more. You can choose what you like for each of these categories.
    I recommend NHibernate with FluentNhibernate and Linq2NHibernate as orm.

  2. @Mike Borozdin

    No, I haven’t had a chance to play around with the Entity Framework. Personally, I don’t have any problem with it since I haven’t had a chance to use it. However, it appears to be pretty actively hated. Either way, it (or any other ORM for that matter) still isn’t bundled in the ASP.NET MVC framework, which is what I am hoping for.

    @Paco

    Fair enough. I suppose if you view the ASP.NET MVC framework as only the web portion of an application then it does its job well. However I question how successful it will be if it doesn’t appeal to beginners more. Having a suggested approach does wonders when it comes to getting people aboard. I feel that it just leaves a little too much up to the developer to be a feasible sell.

    @David

    Yes, I’ve been meaning to read through it. In general, Scott Guthrie’s posts on ASP.NET MVC serve as a good example on how to structure your application. However, it still requires the user actively go seek that information. I guess my real question is why doesn’t this stuff come with the ASP.NET MVC download? They have a Visual Studio template, but it is very barebones. The standard Ruby on Rails install comes with practically everything you need, but the ASP.NET MVC install makes you go find it all yourself.

  3. "Web application frameworks are expected to come with all the necessities to get a basic site up and running."

    The reason Asp.Net MVC is not meeting your expectations in this regard is because it is a UI framework, not a web application framework. It’s like complaining because your sedan can’t fly.

  4. @Liam

    Fair enough. I wonder if the ASP.NET MVC team’s goal simply differs from mine. Personally, I feel that if they ever want to gain mainstream acceptance they’re going to have to appeal to a broader audience.

    Again, it’s great that we’re allowed to do what we want when it comes to validation, persistence, logging, unit testing, etc. but it seems like they’d do themselves a lot of good if they provided some built-in guidance on these features.

  5. @Liam

    Yes, I’ve been following and contributing (comments, not code) to the S#arp Architecture project ever since it first came about. I commend Billy McCafferty on his work and I kind of wish that it were ASP.NET MVC instead of what we have now.

    As I stated in the post, there’s a significant difference between being allowed to go outside the box and being forced to. It’s a matter of opinion to be sure, but I think ASP.NET MVC will have some serious adoption problems if it doesn’t at least attempt to provide a suggested way to do these things.

  6. I think the .NET target audience is much different to rails. In the enterprise arena flexibility in the model is essential with legacy databases coming in all shapes and sizes. While ASP MVC could have provided more guidance in the Model, any strict rules would be it’s death.

  7. @Craig

    Excellent points. I agree that the .NET target audience is different than that of RoR. I also agree that any strict rules would be its death.

    However, one major difference in the target audiences is that the .NET audience tends to be more enterprisey. By that I mean a lot of the .NET audience is composed of large-scale businesses who are wary of going OSS in their software. In that respect, I think ASP.NET MVC is going to see a lot of reluctance from their core user base. Without a set of guidelines to abide by, developers are essentially left with only OSS options, which are sometimes frowned upon in the business world. While strict rules would be equally as bad, it doesn’t seem like such a stretch to provide a suggested Microsoft way that could be substituted out as needed.

    The NerdDinner documentation is a great example of this. I think that if Microsoft just shipped ASP.NET MVC with the NerdDinner inner workings baked in (Linq 2 Sql, validation classes, etc.) it would be far easier to adopt.

  8. LINQ to SQL will still be supported. It’s part of the framework and they don’t deprecate large chunks like that (which is both good and bad). It may not be enhanced, but it’s not going away.

  9. I think the original post misses the point of MVC claiming ASP.NET is only VC. MVC is about the seperation of concerns, which this framework complies with. Whether Ruby on Rails is more specific in offering a solution for the model is a different matter. I would actually be against MVC forcing you to use Active Record as a pattern or any specific technology such as L2S, Subsonic or what have you.

    Those would fit more as templates that could be added on to MVC if someone wants them. And in fact the S#arp project does this with NH.

  10. I like the point that Rails is one end of the extreme (bundles all of ActiveRecord) and .NET MVC is on the other (no ORM guidance included)

    I prefer the Merb (and hopefully Rails 3.0) approach: including helpers for a finite list of ORM’s out of the box. That way they meet you in the middle.

    http://www.merbivore.com/

  11. @John

    I think L2S’s future is really the issue here. True, it doesn’t appear to be going away, but Microsoft has made it clear that it won’t working on it going forward. I’m afraid that that alone is enough to dissuade users from adopting it in their applications.

    It seems as though Microsoft is sending mixed signals when it comes to L2S. On the one hand they want us to use EF instead. Yet the latest ASP.NET MVC app they’ve developed (NerdDinner) uses L2S (and quite well, I might add). I think if they just stuck with L2S they’d see a lot more unity in the MVC community.

    @Hadi

    I would be against MVC forcing you to use Active Record as well. It would be nice to have something built-in here to make things easier for first-time users however. Granted, I’m not sure how you would do that with L2S since you need the database set up before you could generate the L2S model.

  12. One thing they are currently developing for rails is ActiveORM. Its a middleware for all the differnent ORM’s to talk to the rest of the VC stack.

    See in the past, only ActiveRecord could really integrate with the VC and do its thing.(like validation messages in the view)

    This middle-ware is where you will find your M in MVC, and the sooner the better. If the community can come together and form a standard then this can help ensure modularity in the end. Also, defining your middle-ware now will help you determine when, where and how your M will tie in with VC.

  13. I that that RoR vs ASP.NET MVC doesn’t make any sense: RoR is something that handles everything for you, while ASP.NET MVC is just a more testable, more "separated", more web-standard compliant alternative to ASP.NET web forms.
    It’s just an UI pattern, if MS had included a conventional way to access the Model, everybody would have bitten them badly: there are so many different ORM in the .NET space. Furthermore, most enterprises might rebuild the UI of their web apps every 3-4 years, but they change their business logic less frequently, so there is the need to keep a legacy code base, and make it work with ASP.NET MVC. If it enforced a convention that would have not been possible (or much more difficult).
    Just to prove this, at the moment I’m working on the rewriting of a web app, but most of the services for data retrieval are still in COM+ components built in 1997 by people that left the company. So we must stay with these.

    What would have been a beneficial comparison would have been comparing the way ASP.NET MVC handles controllers, subcontrollers, how it passed data between controllers and views, with the way RoR does the same things. Complaining that ASP.NET MVC doesn’t have the same things that RoR has is useless.

    FuBu MVC is going to address the database-to-view approach as RoR does, but not sure at which stage of the development they are.

  14. I think Microsoft was bound by the fact that if they picked a particular persistence technology to integrate with ASP.NET MVC (which would have been Linq To Sql or EF) then they would have likely pushed away the very early adopters which would have made it successful.

  15. @Simone

    Fair enough. So if ASP.NET MVC isn’t meant to be a rail competitor, I suppose the next logical question would be: why not? It doesn’t seem like such a stretch to make it one. The framework doesn’t have to be so opinionated as to prevent you from going in any direction other than the one provided. However, I think the framework would have a far better chance at surviving if it came with a few more bells and whistles. As it is now it seems a little too barebone. But as people have said before, RoR is a much more mature framework so who knows what the future holds for ASP.NET MVC.

    @Justin

    That could be. It probably doesn’t help any that Microsoft has been very reluctant to incorporate any third party libraries into their frameworks in the past. Personally, it felt as though L2S was the original choice, but then it had to be toned down about halfway through ASP.NET MVC’s development when it was announced it would no longer be enhanced.

  16. MVC [i]does[/i] come with an ORM. In fact, it comes with two if you consider Linq2SQL an ORM.

    All you have to do is right click on your model folder and pick "Add New…" That’s not particularly onerous.

    Are you unhappy that MVC doesn’t implement the active record pattern? What specifically would you change if it were up to you?

    BTW, model guidance is already available for beginners who seek it: http://www.asp.net/learn/mvc/#MVC_Models

  17. @Dave

    I’m assuming the two choices are EF and L2S? If so, my problems are this:

    1. I haven’t seen a single guide on using Entity Framework within ASP.NET MVC. True, it is an option, but it’s not exactly the easiest to stumble across when you’re picking up the ASP.NET MVC framework when you start out.

    2. Most guides revolve around L2S and I agree that if I had to pick what Microsoft’s suggested ORM of choice were for ASP.NET MVC, I would say L2S since all of their people (Scott Guthrie, Phil Haack, Rob Conery, Scott Hanselman, etc.) use it in their ASP.NET MVC demos. However — and this may just be me — it doesn’t seem like L2S is that great a choice moving forward if it isn’t going to be enhanced (e.g. will it only support SQL Server 2005 going forward?).

    As I mentioned before, my issue here may be more to do with the fact that L2S seems to fit the bill perfectly, yet it’s in a state where it can’t really be pushed any harder than it is.

    As for what I would do if it were up to me? I would at least put in the option to point to an existing (or create a new) database in the new -> project -> asp.net mvc site workflow. With a database created, the project template could generate the model (even if it is empty) along with the validation interface for starters. This would at least help ease people into the framework and provide a decent starting point. If they wanted to strip it all out and substitute in their own ORM of choice and validation framework, then that’s completely up to them. But to give an empty Model folder as the default way to start an ASP.NET MVC project is expecting a bit much of the user.

  18. @Dave

    Post edited to include the suggestion in the comment above. Not sure if it’s the best way moving forward, but it strikes me as a reasonable way to provide some basic guidance without forcing a methodology down the user’s throat.

  19. thanks for this article… I’m hearing increasing sentiments of “nuts to .net I’m going to ruby” and I’m trying to understand it all. Most of it sounds like a lot of “ooh look at me I’m raging against the machine” anti-ms hooplah, and while I am a commited .net developer, I’m always open to exploring new platforms and frameworks (I started out in php after all)

    It sounds like to me the only reason people prefer ruby is that it has things like the data model built in. It seems asp.net mvc would benefit from merging with the Subsonic project and have that be the default model. It should still support out-of-the-box orm or custom data models (dataset, etc) but Subsonic keeps in line with the open source, mvc pattern so much, and it’s so easy to use that in my opinion it’s a perfect match.

    If they seamlessly integrated the two they’d have one serious contender against rails!

  20. +1 for Sharp Architecture. The broad collection of technologies means there’s a lot for beginners to get their heads around, but thanks to nicely thought out Visual Studio templates, you can going in the right direction straight away.

Comments are closed.