What ASP.NET MVC Could Learn From Rails

Most developers that are interested in bettering themselves really do want to hear both sides of the story. They want to understand the strengths of other platforms, not so they can move, but so that they can understand how to make their own framework/platform better. When you read this post, I hope you will read it with that in mind. I hope you will see this not as me criticizing your platform, or someone else’s work, but instead as me saying “here is what I think is cool about this other platform, how can your platform get in on that?”

A Tale Of Two Frameworks

There was a time when Ruby on Rails was the hottest thing on the block, and many ASP.NET developers pined for the day when we could leave behind controls and viewstate and move into the glorious world of web development. Cause what we were doing wasn’t web development, don’t kid yourself. Then ASP.NET MVC came out, and a lot of people (myself included) jumped on that bandwagon and have never looked back.

I have been very happy with ASP.NET MVC for a long time. It gives me a simple to use framework that gets out of my way and lets me write real web applications. And I love it! But there is just one problem, websites are quite often complex beasts and ASP.NET MVC only solves a small part of the puzzle. Every project I start I have to pull in a membership system, migrations, an ORM, an IOC container, logging, testing framework, etc… I have to find and plugin all of these tools every time I want to do build another site. (Nuget has helped with the finding and integrating part immensely!)

I guess this is to be expected though, ASP.NET MVC wasn’t really meant to be an opinionated framework. They wanted to produce a framework which would have broad appeal across the hundreds of thousands of .NET developers out there. Not an easy task! They also wanted a smaller framework that they could release in short cycles. Based on their goals, I’d say that they have done a great job.

But because of this they couldn’t just pick different frameworks and include them as defaults. First of all, there were few choices that would not have been controversial. Secondly, if they had made controversial decisions, the framework would have been rejected by early adopters and not seen the adoption that it has now.

Creating a generic framework is fine, as long as you understand what you are giving up to get there. The power of frameworks like Ruby on Rails, Django, or CakePHP is that they span the whole stack. While this might lock you down to doing things in a certain way, in the end the benefit derived from the tight integration is very often worth it.

Walking Through The Problem

In order to demonstrate this, let’s take the example of authentication in a web application. In ASP.NET MVC we have the normal ASP.NET authentication mechanism which we can leverage in order to have users and roles, but as most of us know, a lot of people end up rolling their own or looking for an outside solution. Why? Because the user is part of our domain, and the ASP.NET authentication system forces us to use their tables, stored procs, db deployment tools, etc… It is clunky and not extensible at all. So let’s say we want to build an alternative, what would we have to do?

The first we need is a model that represents a user, we can either include this in the framework, or maybe just let the user define the class that they need, and then implement an interface for us to interact with. Okay, so how do we get the tables in the database? Well, we could create some scripts and put them in the project, then the developer can run those to create the user tables. That doesn’t seem very awesome, what if they aren’t running SQL Server? Yes, some of us do use .NET without SQL Server. What if they need to automate creating the database for testing? Also, how much does it suck to have to manually run the scripts on every machine you need to deploy to?

Well, we could write code to connect to the database and run the DDL to create a table. That would be more automatic. But again, what database are they running, which connection do we use, how do we let the user modify their user object to fit their needs if we need to create the table? Arrrrgh! Okay, let’s just punt on that and say that we will just create scripts for a few databases, and let the user modify and then run them manually, or integrate the scripts into their build process. That sucks.

Now how do we get the user model in and out of the database? We don’t really know how the developer is going to be doing data access, so we can’t pull the user from the database within the framework, we will have to force the user to implement a class that we can call and get users, in the same way that the provider model is currently implemented in .NET. This isn’t terrible, just inconvenient.

So now we are at the point where we have a database table, and we can pull users from the database. The only problem is that the developer has had to implement an interface on his user object, manually edit and run scripts, implement a persistence mechanism (most likely an ORM), and implement a provider to allow us to perform CRUD operations on users. And we are just getting started! What about creating a controller, views, adding routes, validation, sending e-mails, etc…? There are a lot of pieces that go into a successful authentication mechanism, this isn’t easy stuff.

In the ASP.NET MVC world, all of these problems may seem overwhelming. Sure, we could implement a full solution, but we’d have to make a lot of assumptions and force the user into tools that they might not be using. Or we include our own tools, and bypass their stack in the same way that the ASP.NET providers work. This disconnect is what frameworks like Sharp Architecture try to solve, but third party libraries could never depend on frameworks like this until their adoption reached a critical mass. Otherwise they would be spending a lot of effort, for every little return.

How Would You Do This In Rails?

In Rails there are a few different frameworks available to do authentication. The one that I have used is Devise. In order to use Devise, the first thing we would do is to add the gem to our Gemfile (a gem is like a NuGet package, if you don’t know what a NuGet package is, go here) with a line like this:

gem 'devise', '~> 1.3.4'

Then we just run “bundle install” and the gem is installed into our project. Now we have to configure devise. We can run this command (you can type out ‘generate’ instead of ‘g’ if you want):

rails g

And it will show you all of the generators available to you. You will see a section for Devise. Devise is able to hook into these generators and do some really powerful stuff. We can see from this list that there is a generator for devise called “devise:install”. We can run that:

rails g devise:install

Now Devise has installed its configuration file into your app, and you are almost ready to go. You’ll notice there is another generator just called “devise”, if we run that it tells us to give it a model name so it can generate a User model for you. Because everything in Rails has a place, you simply run this command:

rails g devise User

And it drops User model into your /app/models folder, generates a migration for you, and puts routes into your routes.rb file. Now all I have to do is run my migrations (I can edit the migration or create another migration to edit my user table, allowing me to completely customize my user):

rake db:migrate

And now my database tables are created and everything is ready to go. I can put this on my controller:

before_filter :authenticate_user!

And now that controller will redirect me to a login/signup page, allow me to create an account, send confirmation e-mails (if I want), etc… I also have a number of helper methods that I can run like “user_signed_in?” or “current_user” in order to interact with users on a more fine grained level.

What Happened There?

Well, you saw the power and productivity of a full stack framework. Devise knows what tools you are using (or how to integrate with them), and where everything goes. Because of this we don’t need to tell it how to create a model, create database tables, save/retrieve users from the database, how to connect to the database, how to send e-mail, etc… These are all configuration and sensible defaults that have already been setup in your application.

And for anything that isn’t automated, there are Rails generators that we can hook into to create config files, add routes, views, and any other assets. We are able to do this because most everything has a place in a Rails app. Rails is a very opinionated framework, and it shows. If you follow the “Rails Way” then things will be smooth and super productive.

How Do We Make ASP.NET MVC Better?

That is a very difficult question. You see, the Rails community long ago agreed to go along with the “Rails Way” in exchange for increased productivity and integration. I’m not sure that the .NET developer community would respond favorably to the kinds of changes which would be required to bring ASP.NET MVC up to the level of integration that Rails enjoys.

This doesn’t mean that they can’t come close though. One thing they could do is start to favor certain tools more in the framework. Start to setup conventions and tools that developers are expected to use, and let them know that if they stray, they are on their own. However, the problems here are obvious. The tools that are going to be made the defaults will be Microsoft’s own tools, like Entity Framework or MEF. This could create some serious friction with the developer community if they start to integrate too tightly with these tools.

An MVC Uber-Framework?

Another interesting path would be to see some full stack frameworks spring up on top of ASP.NET MVC. Maybe Microsoft could implement another framework on top of ASP.NET MVC which would be fully integrated, but could be tossed out if you just wanted just the underlying web framework. As long as this framework was simple and powerful enough, you would probably see a large number of developers jump on board, which would give OSS creators a reason to integrate with it. On the MS platform, a tool like this usually has to come from within Microsoft itself, otherwise it has an extremely hard time gaining any momentum.

I can see a lot of eyes rolling and hands shooting up after that last paragraph, but hear me out. If Microsoft continues down the path they are now, and they start integrating things like Entity Framework and MEF as defaults, but not truly integrated, then all we are going to get is a bunch of code generation when we start a project. This isn’t going to help OSS developers extend the framework. But, if they could instead tease out the web layer from the rest, and build a more integrated application stack on top of it, that would go a lot further. I’d love to hear people’s feedback on this.

Will It Change?

I don’t know! ASP.NET MVC is a fine framework. I just don’t feel like it is as productive as it could be. Good, solid, testable web development just doesn’t have to be as hard as it currently is with ASP.NET MVC. ASP.NET MVC has given us a good start on the web layer, but hooking up our applications to this front end is often repetitive, clumsy, and cumbersome. All I want is for my whole stack to play nicely together, is that really too much to ask?

Be Sociable, Share!


  1. A'braham Barakhyahu

    Good article. This also shows what would be needed for client side MVC to be adopted widely.

  2. Very nice. Thank you.

  3. I love the comparison with the authentication bits – that’s a whole pile of horrible that Msft desperately needs to refactor. We dealt with a couple refactors over the web authentication scheme in our own project- very little has changed since .net 1.1 or 2.0 and it’s very rusty and neglected.

    I like the approach the mvc team took with IOC- asked for ideas, even posed the notion of using the CommonServiceLocator and thankfully threw it out.

    I’m confused by “build an uber framework” – msft is fully capable of throwing bodies at a problem until it’s a 4 headed monster and we really don’t need that. That’s when we get things like Wcf 1.0.

    If things like authentication and other pain points are addressed similar to IOC (implement if you want it), then doesn’t that address the problem equally well? I like the configuration options of ruby, i think it would be interesting if mvc had a congruent internal dsl for wire up with these sort of “core components”.

    If this stuff bleeds back into asp.net, then that’s great, but I just can’t see myself doing another standard asp.net web app for the same reasons you list.

  4. Justin Etheredge

    @Steve To me the problem is that a website is a web front end, an application domain, and a data store. Rails gets a huge productivity advantage by implementing all three layers. This allows OSS developers to develop tools which work across the entire stack. The ease of integration, as I showed in my post, doesn’t just stop with membership, but with any number of other gems available. Now, I know that a lot of it comes from the flexibility of Ruby, but being able to count on the ORM, Migrations, etc… would go a long way.

    Now I know that there is a huge fear of “throwing bodies at a framework until it is a four headed monster”, but I think the MVC team has shown that this doesn’t have to be the way that MS runs projects. I think they could do it, and do it will, they just need the right people and the right goals.

  5. Sampath Dassanayake

    Have you guys seen http://sharparchitecture.net
    This is kind of an uber framework built on ASP.NET MVC with a lot of plumbing already done. I’m loving it!

  6. Justin Etheredge

    @Sampath Yep, I even mentioned it in the post. My problem is that the problem isn’t solely limited to how productive you are when writing code from scratch. A large part of the problem comes from other developers being able to write plugins or add-ons that can fully integrate into your application.

  7. Hey Justin,

    Nice article. I am one of those guys who doesn’t use SQL Server with .Net. I use MySQL. And yes, migrating to mysql was tough in the beginning but I made some shortcut classes and tools of my own which eased the pain later on.

    And I have never used forms authentication and many of the custom built ‘shortcuts’ provided by ASP.Net for exactly the same reason as you specified — they’re not so customizable. I roll my own, and frankly I’ve had to write different code for almost every web app I’ve made.

    Although I haven’t any experience with Rails cause I work on Windows, and my server is also Windows, and I haven’t been able to find good Rails based tools for Windows… On my limited education I think ASP.net MVC is not entirely bad anymore.

    Talking about that authentication example specifically; I use a SigninRequiredFilter in my own apps, which I made myself. I decorate my controller methods with this filter if a Signign is required to visit that page, and it does exactly the same thing as the filter for Rails.

    Frankly I hated it when I had to write ASP.Net Webforms code, and I was gravitating more towards PHP every day, but ever since I went to ASP.Net MVC 1 (after a lot of hesitation), I can’t code webforms again. I migrated couple of my webforms apps to MVC cause I couldn’t bear to look at that code.

    ASP.Net MVC 3 look good, and the razor viewengine is nice…

    In my code I don’t use helper methods opting instead to write pure HTML.

    My experiments with ORM like Entity Framework (with MySQL) failed, and I never went the Nhibernate way. I don’t unit test, and I fix when it breaks.

    I don’t write apps for enterprise so this works for me because my apps are 100% in my control.

    ASP.Net MVC gets a big thumb-up from me.

    Any suggestions if I want to use Rails on Windows?

  8. I agree, if any group has demonstrated the ability to maintain focus it’s the mvc team. And i was glad to see them go along with Scott Gu in the reorg for that very reason.

    I see the point of ruby having it’s fingers in each of those areas, but I wonder about the extent to take asp.net mvc in that direction and then how to go about doing it. It’s a super-fun conversation to have.

    More ponderings than concrete suggestions really:

    – I would worry about the “supported technologies” like EF. I work in a non-Msft db environement due to a lack of driver support for our ‘nix platforms. EF could leave us stranded.
    – I worry about things like MEF being supported for the same reasons as you (I think): MEF integration should be seen as a part of a larger strategy, and not an end unto itself. The latter creates more concepts to wrap your head around before being productive while the former could provide quickly understood extension points without (hopefully) denying access to more advanced functionality.
    – How would nuget have to change to support the kind of integration required?
    – If a common internal configuration dsl could be built out, the configurability points with extension methods could be pretty powerful.

  9. Well I’m sorry, but I don’t really think that this will ever happen ind the .NET space. We are simply to locked on, as you said, Microsoft delivering the ground pieces for stuff.
    One of the differences that makes Rails great as a full stack, and what would make ASP.NET MVC horrible, if MS made it full stack. It’s that every little feature in Rails is created because there was a need for it, in a real project.
    Then he same person that needed the thing, helps implementing and designing it.
    In the MS realm, then the MVC team is just making MVC, maybe some small sample apps, but they are not making a whole company’s apps on it, like 37signals do. If there is a real app being build at the same time, then it will properly be build somewhere else in MS, and they can’t properly mess with the milestones, other that request a feature, and hope that it will get implemented.

    I like ASP.NET MVC as well. But if you like a full stack of love, then .NET is simply the wrong platform based on it’s democratic dictatureship (that MS does all) and its culture (I need finished, tested, and used-by-all stuff + I don’t contribute to projects, I just whine).

    Even the way that MS is treating Backwards compatibility is a threat. I wrote a little post about it here: http://deldy.dk/post/reversed-backward-compatibility

  10. So what you’re saying: if someone created a NuGet package that contains a PowerShell script which, on install, creates a DB table, includes a User model and creates an authenticationfilter (which, by default, is applied on all action methods), ASP.NET MVC is equal to rails? Seems feasible :-)

    More: if you base yourself on the T4Scaffolding and EF code first, creating this package should almot be a no-brainer…

  11. You have totally hit the nail on the head. I had played with rails a couple of years ago, but since working for a Microsoft software house I have been more focussed on their offering.

    I have been kicking the tires of ASP.MVC for a while and convincing myself that they had finally done it and produced an offering similar to rails.

    Then last weekend I picked up a copy of the newest rails book and it hit me in the face how different the experience was.

    With ASP.MVC I spent a lot of time and I mean a lot of time learning about IoC, decoupling and various different methods of talking to databases and had found it difficult to know where to go. Do I use Ninject or Unity or some other library that I have not heard of yet, but someone on stackoverflow thinks is the second coming. If I make any of these decisions is it going to cause me problems later on. By this time I had forgotten the problem I was trying to solve.

    With rails the most difficult bit was making sure all my gems were up to date and I was using the latest version of ruby and that was not really that difficult.

    I did not have to think about any of the issues faced with ASP.MVC because someone smarter than me has already made the decision and I can live with that. If I cant I can always change it. This allows you to figure out the best way of solving a problem rather than spending all your time building an environment.

    Still I do like ASP.MVC. I also feel that NuGet could, and is providing the solution to this issue in the ability to quickly add things to a project.

  12. I would urge you to have a look at orchardproject.net, and then come back to this article ;)

    I mostly just browsed through the article, since I feel most of what you claim has been solved using the modularity Orchard offers.

  13. The problem is yours isn’t a like for like comparison. You compare an out of the box framework for authentication that someone has put a LOT of time into (Devise), to writing your own.

    Your article should compare out of the box in both Ruby and MVC, and then writing a custom mechanism from scratch in both.

    I don’t disagree with the point of the post necessarily, just think the example is flawed.

  14. Justin Etheredge

    @Maarten I think you missed the biggest point in my argument. The power of Rails comes from its open source community. The open source community can create the amazing gems that it does in large part due to the tight integration with all of the different pieces. Sure a NuGet package which generated some stuff for me might help me be a bit more productive, but that is kinda missing the point.

  15. Justin Etheredge

    @Simon I wasn’t trying to show an apples to apples comparison. I was trying to show the issues with creating a package like authentication when working against ASP.NET MVC. Then I was trying to show that in Ruby, because of the integration, this kind of thing exists and is super easy. The whole point is that if the integration points were there, you would have to be writing this code! There would already be a “Devise” for ASP.NET MVC.

    Sure, I could have shown how to build something similar to Devise for Ruby, and the end result would have been the same. On one platform it is very doable, on the other, not so much.

  16. @Justin “The open source community can create the amazing gems that it does in large part due to the tight integration with all of the different pieces.”

    Replace “gems” with NuGet packages and you’re at the same level? Seriously: if MS offers ASP.NET MVC 3 and the NuGet feed (or a different feed) contains a series of “NuGems” that, for example, provide security out of the box, it’s identical, no? Nothing is currently blocking the .NET community to jump on that bandwagon?

    This is currenty the case already. Need IoC? Install-Package Autofac.Mvc3 or Install-Package MefContrib.MVC3. Need jQuery? Install-Package jQuery. Need X? Install-Package X.

    Some of these packages are just simple things that dump a binary in the project, while others really add classes, modify configuration, …

  17. Justin Etheredge

    @Maarten Okay, I think we are misunderstanding. Just providing a package system on top of a web framework does not make it a full stack framework. Did you see in my example how Devise was able to fully integrate itself without hardly any work because all of the pieces are there? It can generate a model (knowing what my ORM is and knowing where my models go), it can generate migrations (since Rails has a migration framework built in), etc… it can do all of these things because all of the pieces are there.

    So yes, I can pull in package X and Y, but most likely package X and Y are not going to play well together, and they are only going to provide integration at the web layer, because that is the only thing that they can reasonably know about.

  18. @Justin Clear now. Well, I do feel that something like that is possible currently, it’ll only require someone to step up and create some glue work (much like Devise is the glue work in RoR, like Simon said above.

  19. Justin Etheredge

    @Maarten Okay, but how? If I want to create assets in the database, how do I get them in there in a testable, deployable way? How do I create a model? How do I do database access? How do I add routes? This is my whole point. Since ASP.NET MVC stops at the web layer, packages can only integrate so far.

    Yes, it would be possible to do all of this in ASP.NET MVC, but we would need a framework built on top of it that included all of these tools, and provided standard places for pieces to go, and provided apis for creating some of these assets. We would also need something akin to generators which would allow us to create assets after the package has been pulled into the application. All of these things are possible, but they need help from the framework.

  20. @Maarten, @Justin

    Forgive my intrusion. I think you both have your points, but if I may:

    I’m not an expert on Devise or Rails so please forgive my ignorance. From your post, I’m assuming that Devise only knows how to *integrate* with certain other frameworks, be these the core Rails framework or other Gems. I assume that it knows about your ORM if you’re using ActiveRecord. But tomorrow if I use something else it won’t know. It knows about Migrations because as you point out, Migrations are inherent to Rails.

    The point is that, yes, there’s a open source community behind Rails that do provide these Gems. In .NET this has been quite limited for many factors, some of which include Corporate policies, entry to OSS frameworks and lack of experience by many 9-5 “enterprise” developers. NuGet (and when I say NuGet I also mean OpenWrap) have quite a lot of potential to change that and I think it will open up more interaction with MVC and the ecosystem around it.

    Up to now MVC was not so opinionated in regard to Models. Some of us like that, others didn’t. Now in MVC 3, that has changed. You want a Model, you have Entity Framework out of the box. Whether in 6 months there will or will not be a Migrations story and how NuGet will interact with it, time will tell. NuGet packages are already taking advantage of this Model story. And I’m sure when and if a Migration story appears, they’ll integrate with that also.

    The key here however is that before NuGet/OpenWrap, I’d agree with you wholeheartedly that there was a lot of friction in getting infrastructure code up and running (and I’ve blogged and complained about this myself on numerous occasions). However, now I think things are changing.

    Of course, Rails will always have certain privileges being based on a dynamic language, but in terms of packages and interaction, I think we’re not doing so bad in .NET.

  21. Justin Etheredge

    @Hadi I agree completely. Devise is able to do the things it does because these are things built into Rails. Only a certain part of that is due to Ruby and its flexibility. And yes, if I were to move off of ActiveRecord it wouldn’t know how to interact with another framework, except for Mongoid, which it was written to use as well. And it knows where to put things and how to create things for this same reason.

    But the point is that 99% of Rails apps use ActiveRecord and migrations. Because they were in the framework and all of the tools out there are built around them. This streamlined approach affords this ability.

    And as you said, they are including EF 4 out of the box, but they have to do more than just include the assembly and do a bit of codegen. Cause the problems still exist from the packages, where do I put things? How do I get a connection setup? etc…

    The MVC community is making huge strides, and NuGet is a big step. I just think that there is a bigger opportunity out there to make ASP.NET MVC developers much more productive than they are now.

  22. Hi Justin,

    # couldn’t agree more #

    Every site i start, I explicitly turn off membership/profile/roles in the web.config.

    It’s so frustrating how those features were invented in the initial ASP.NET framework and have been kept alive (WHY!?) till today.

    The .NET team really really REALLY need to break backwards compatibility and release vNext with some much needed improvements -> very similar to your suggestions. Seriously – who the hell uses windows authentication? (if u dare suggest sharepoint, please go kill yourself). We need to make the framework a bit more plugable AND get some of the basics right .. just like how RoR have some of there basics done pretty damn good.

    ASP.NET MVC has been a lifesaver for us MS dev peeps .. and it couldn’t have come sooner because i reakon there would have been so many who were so close to jumping ship. Some already have but lots are staying.

    If only we can get some basics fixed up. Try-in point: Create a new ASP.NET MVC3 web site. Now try and handle a custom 404 page. Does that work? No :( (eg. http://bit.ly/lbaqZO ) That’s pretty embarrassing .. if that SO question is accurate.

    I just wish MS would think about (the massive number of) start ups/small/mediums instead of just large companies / F500’s. Then we would get some much needed love. Smaller release cycles. More fixes more quickly. etc. etc. U know the spin.

    For me, I’m looking to do ASP.NET MVC3 with RavenDb. EF has just killed me .. and this has been after using RDBMS’ for .. well .. since 94.

    We all need to be more agile and follow some of the smarts from RoR .. and allow the .NET community to decide what works best .. instead of MS always having to have a solution (which doesn’t always equal the best in the industry .. ie EF, etc). Have some faith in us MS and stick to real core stuff.

  23. @Justin, check my talk at http://channel9.msdn.com/Events/MIX/MIX11/OPN07. Forget the point I’m making about enterprise feeds, but do have a look at how I standardized things like authentication into “contracts” shipped in NuGet and how their implementations also come in via NuGet. The only thing it takes is for the ASP.NET MVC community to build stuff similar to my very trivial example and the ball is rolling.
    Also look at the scaffolding functions Steve Sanderson is spreading through NuGet. Treating Models like they should be treated, generating data access code (either through EF directly or by generating a repository in between). He’s even generating unit tests for that code. Bottom line: Steve is setting a standard that I see a lot of people are following in the NuGet space.

    We’re not there yet, but we’re getting there. And I think it’ll be sooner than people can imagine.

  24. Justin Etheredge

    @Maarten I’ll definitely check it out. And believe me, I want to see ASP.NET MVC get there. I hope that more discussions like this will bring the change around faster.

  25. Well first off if Microsoft made a full stack framework people would be screaming how it sucked and blah blah blah, just because it was Microsoft. Even if the said stack was near perfect. I’m not sure how the Ruby or Rails community is, but the .NET community seems to hate Microsoft and that is the problem. You get people building separate frameworks just because they don’t like how Microsoft did something. I don’t think this is bad in anyway. But personally I get sick of people saying how much Microsoft sucks while still using Microsoft products. Justin, I think you suggestion of building a framework like MVC to be agnostic, THEN building a more opinionated full stack framework is a real good solution. Things are changing at Microsoft, look at Nuget, maybe real community collaboration for other things isn’t far off.

    I have a feeling any such effort would be met with disdain and anger though. Look at the reception LightSwitch got.

  26. It’s crazy how many intelligent capable devs I see making these same arguments/points. In the end though, I still don’t see any new projects popping up (excluding FuBu MVC). Seems like it is just time to create a new GitHub repo and get to work on a solution, no?

    I bet the response from the .NET community, especially the .NET devs now doing Rails work as well would be huge.

    Great article and I agree, but I think it is about time to take action and make things happen!

  27. @Maarten the notion that “NuGet is there – all we need is the community to step up” has been the response of DevDiv forever. It’s not a bad one – they don’t want to tell the community what to do, which makes sense. They are the music makers – we do the dance.

    However that lack of prescription leaves people to wave their arms continually – whereas the Rails guys come right out and say “do it this way dude”.

    Many people have tried over the years to change this – namely me – and to drop the pieces in to help things along. For instance – I sent some prototype code to the team to implement and ActiveRecord interface that *any* ORM could plug into.

    But an ActiveRecord pattern doesn’t coincide with existing ORM offerings (EF, LinqToSQL which use Unit of Work) – so that doesn’t make sense to them.

    You could setup an IQueryable Repository Pattern to build on top of – indeed I did just that (http://mvcstarter.codeplex.com) and I kicked out a free video to show how to build on top of/use the opinionated stack I built.

    I don’t want to grumble and say “ho hum no one cares” but really – that *is* the truth. If it doesn’t come from DevDiv, it doesn’t exist. I know it sounds grumbly and negative – but consider that this Full Stack thing is something I’ve been trying to create for years.

    It just doesn’t take hold unless Phil and team do it. And they won’t. They build the Frameowork and that’s where their mandate ends.

  28. @Rob that might be where Phil and team leave off but it doesn’t have to mean where Microsoft leaves off. Doesn’t Patterns and Practices already kind of do this? Create the “Do it this way” things? Also a lot of what to use tech wise comes from top down in organizations, from people who don’t necessarily understand that the Microsoft way may not be the best way for a given situation.

    For me the real problem is knowing about other solutions. And which one to use when, ASP.NET MVC? FubuMVC? OpenRasta? Or WCF? ServiceStack? etc etc.

  29. This is why Sharp Architecture is appealing to me for green field projects. Sure, it doesn’t cover all infrastructure concerns, but it gets you much further than File > New Project.

    Several people have made the point that if Microsoft came out with a full stack, there would be all kinds of screaming.

    Instead, would it work for Microsoft to provide common interfaces and registration hooks for these needs (repository, authorization, logging, emailing, caching, etc.) and a default Microsoft implementation, but let developers swap out open source implementations with NuGet that went beyond that default implementation? Maybe something like IDependencyResolver or the EF repository-style scaffolding.

    There is still the risk the interfaces become lowest-common-denominator, but it would be a start.

  30. What if .NET developers stopped identifying themselves as .NET developers? What if they just considered themselves to be developers? I think we’d see a lot less, “how do we get Microsoft X to catch up with Y?” and a lot more “Let’s just use Y because it already does what we want.”

    Seriously, the amount of energy being poured into playing catch up is saddening. Imagine if all of that effort was poured into the tool that’s already better at this.

    There are no .NET Developers. There are only developers who have been brainwashed into thinking they can only write code in .NET.

  31. It’s difference in MS monolithic thinking, and the Unix-like thinking of small programs that work together.

  32. How many projects are build via the RAD Rails methodology ? All your views, domain logic, database access ORM – all thrown into one Rails project? What if you want to separate out and your rails is just a thin layer and you want a service approach – do you create two rails apps and one calls the other ?

    I’m trying to imagine create a large application base for a company like I am in .net – where asp.net mvc is but the view layer calling back to many services.

    If we want to just to just throw all our data access into one project and use folders then we have MvcScaffolding, EF Code first is doing migrations soon, is you just want some rad scaffolding, look at MvcScaffolding.

    You can take the T4Scaffolding and generate EF code first based generation of a complete authentication layer.

    I think MS tends to create the framework for the community to build up their own implementations. Nothing is stopping us from building on top of this, just in the same manner dhh wrote rails on top of ruby, I don’t know if he asks ruby to implement rails, no, he took ruby and built rails on it.

    There is so much out there, so many opinions on how things should be built. ie. above I heard Sharp Architecture that is everything + the kitchen sink, and then I hear someone like ‘xyz’ (not going to say names) say it’s way overdone.

    I do see progress, it took MS over 10 years of me using Hibernate/NHibernate for them to see a ‘poco’ based ORM was a right decision – they went the wrong way with EF1 and now they are making the right progress going the right way.

    There was an open source community (still is), called Castle – they built a front controller mvc, called MonoRail – they provide an ActiveRecord implementation that sat on top of NHibernate, and provided the DI glue with Castle Windsor. That has been around for awhile. It is hard to ‘compete’ when everyone was stuck using Webforms and no one would risk moving to MonoRail prior to asp.net mvc. Now asp.net mvc comes out and it’s the greatest thing since sliced bread, and yet I have to laugh that this has been going on long before this new fangled shiny toy :)

    Microsoft provides the dev tool (only one), the server environment, the entire stack – so people tend to stick to that stack, as they know this big company is committed to it with a ton of developers pushing it.

    Where are you running your rails apps – you have a large corporate environment with Linux machines running it ?

    This is the same ‘LAMP’ vs. Webform dialog repeat going on again with just some new players at the table :)

  33. Aaron,

    I should add, I can write .net, rails, django/python, java, objective-C, etc… so it’s not really that ‘.net devs can’t write anything else’ – that is a joke.

    I think what happens is, we get work that uses a certain technology, we get on projects with those technologies, and we use what those technologies provide. Right?

    It’s not very often , especially in larger environments, where I can go in and say ‘hey let’s use Rails’. It’s so much more complex than that unless this is just some startup or smaller shop where you have guys there with some great knowledge of that technology.

    But back on topic, MS provides the framework, it’s up to the community to build more on top of it.

  34. Quote @Steve

    “But back on topic, MS provides the framework, it’s up to the community to build more on top of it.”

    … which is the frustrating thing about it. All the developers I know that work (primarily/only with) .NET .. don’t do _anything_ OSS related. Wait -> i’m not saying 100%/all are like that. Hell no. But (what I feel like) is a far majority. I really feel that developers that (primarily/only work with) .NET just use the spoon fed stuff out of MS. I know for so long I was one of them. Like, if it came out of MS’s quality control and into the RTM, it must pass all the ticks, right? Including ‘best practice’, blah blah blah.

    Wrong, IMO.

    Which is why I agree with many here and that is that MS needs to provide a much more open framework. Where all the important interfaces are exposed so we can swap out the defaults. MVC is doing this. Want Spark Views – go for it, etc..

    To do that, we need to break backward compatibility with the current ASP.NET framework and drop lots of wrappers and cruft to clean stuff up. Simplify lots of shit.

    Do we really need ASP.NET to create 404’s AND IIS (7 or express .. forget the others) to ALSO have the ability to create 404’s. (sigh…)

    I love working with MVC but i’ve come to loath EF and certain parts of ASP.NET (authentication / membership / 404/500’s …) so i would love it if the parts we want to substitute could be done with zero friction. I will still be paying for my Windows Server license. I just will be using a 3rd party for XXX. Remember, .NET is really only there so people will be renting/buying server licenses, msdn licensees, software licenses, etc. I’ll still be doing that .. just make me want to do that EVEN MORE. Cause right now .. i’m starting to feel very tired about banging my head against so many barriers for simple tasks. I need to create some lovely art – websites and apps. Not figure out why sometimes my custom 404 page shows but with other routes, it doesn’t. Or why i have to step outside of EF to do some serious stored procedure calls or why trying to get my OO domain modelled into a RDBMS makes me want to shoot myself in the head, these days. I’m spending time doing crap i shouldn’t.

    I want to paint a nice website. Not fix-up and fight with my paintbrushes. My problems should be what colours or techniques i painted with. What textures I should be using. Not dealing with inferior or complex brushes.

  35. […] What ASP.NET MVC Could Learn From Rails – Justin Etheredge has been looking at the other side of the MVC fence, exploring Ruby on Rails, and in this post feeds back some of the good things from the Rail platform which he would like to see brought into ASP.NET MVC. Be sure to check out the discussion in the comments of this one. […]

  36. As you pointed out, the fact that ASP.NET MVC is not opinionated is the problem here.

    The developer has a blank slate. The fact that rails has a dedicated folder structure means you can easily find all the bits. Contrast this to ASP.NET MVC where everything could be anywhere.

    Everything juncture has several choices or more. ORM/Authentication etc, even where I put my files.

    Without these sort of guarantees, there is little that can be done. Any movement to unify will be hindered due to backward compatibility.

  37. Awesome post.

  38. Awesome post.

    I think the answer to why these things don’t work – or haven’t yet worked – with .NET is that a lot of .NET developers are spoiled. The control thing you mentioned can be used as a metaphor for how .NET began to suck – if it isn’t quick-and-easy a lot of .NET developers will bail out and blame the stack, not their willingness to put forth effort to learn how it works under-the-hood and make it better. “If I don’t have a control that does what I want I will bash Microsoft for releasing an incomplete framework and if they give me a control that does what I want in a way that isn’t commensurate with how I want it to be done I will bitch then, too.”

    That’s the reason .NET folks (some of us) have a difficult time adopting opinionated frameworks – we think we are owed precisely what we want, and if we have to code to make it work or to learn how it works well enough to actually DO something, we freak out.

    All around insightful post, sir. Find me at #CodeStock for you have earned a brew on me. Or 10.

  39. Justin, I came here after seeing Scott… Hanslemen? Or was it Gu? yesterday that tweeted in response to this blog post that isn’t this all summed in Nuget?

    “@Maarten Okay, but how? If I want to create assets in the database, how do I get them in there in a testable, deployable way? How do I create a model? How do I do database access? How do I add routes? This is my whole point. Since ASP.NET MVC stops at the web layer, packages can only integrate so far.

    Yes, it would be possible to do all of this in ASP.NET MVC, but we would need a framework built on top of it that included all of these tools, and provided standard places for pieces to go, and provided apis for creating some of these assets. We would also need something akin to generators which would allow us to create assets after the package has been pulled into the application. All of these things are possible, but they need help from the framework.”

    I think you’re missing out on some of the aspects of nuget.

    Those generators already exist. That is the MVC Scaffholding project.

    The MVC Scaffholding project isn’t merely about doing what it does (which is alright, but not great) but it’s about giving you a working project that lets you create your own custom generators to DO ANYTHING.

    On your comments about migrations, there’s a nuget package for Fluent Migrator.

    So to answer your question “HOW?” would you create a full stack support package. It would probably go along these lines:

    Modify MVC Scaffholding to be able to generate the classes you want, when you generate a Model class have it generate a FluentMigrator class also. Make the package dependent on FluentMigrator.

    Now I would agree that MVC could use some additional opinionated structure since it’s almost a free for all of where you’re going to drop the generated files into a project etc.

  40. I liked the opening paragraph of the article, because I’m all about learning new stuff in an objective manner. Unfortunately I feel like the article pretty quickly devolved into a “isn’t Ruby great” article. You spend a great deal of verbiage showing how difficult it is to set up a custom membership in .NET, then tell us how simple it is in ruby, you just need to type.

    gem ‘devise’, ‘~> 1.3.4’
    rails g
    rails g devise:install
    rails g devise User
    rake db:migrate
    before_filter :authenticate_user!

    Why yes, how blindingly obvious that that is all I need to do. Perhaps once you’ve done it a dozen times it’ll become second nature, but please don’t try to sell those incantations and simple and easy.

    As others have said (or at least implied), if Microsoft came out and said, “here’s the stack, do it this way” everyone would scream about how “arrogant” they were and how they want freedom to pick best of breed and not have Microsoft shove it down their throats.

    I guess I’m just an old curmudgeon (been in this field since the early 80s) but I’m having less and less patience for the entitlement and self-important attitudes I see from (mostly younger) developers.

    P.S. Although I’ve pretty much switched to using ASP.NET MVC whenver I can, I still get sick and tired of the WebForm-bashing I constantly see. I know all the “cool kids” have moved on to MVC or Ruby, but please note there are a lot of sites out there built on WebForms that are wildly successful. Once you’re built a buy.com or godaddy.com you can start bragging. Until then please stop telling me how much better you are then the rest of us.

  41. Justin Etheredge

    @Craig I never said those “incantations” are easy to remember, but for what it’s worth they are common commands when dealing with Rails. The ones that aren’t common are documented, but that is going to be dependent on the project you are using.

    Sorry you feel that my post is slanted in some way. Yes, I think Ruby and Rails are great tools. But they are also very focused tools. They do one thing, and they do that one thing very well. So I don’t think MVC sucks, on the contrary, I think that for what it does, it also is an excellent framework. All I was trying to say is, it doesn’t go far enough for my tastes.

    But hey, all I’m trying to do is point out some gaps that I think MVC has, and what I think it needs. If you, or others, take that as I am bashing MVC then I don’t think that anything will ever get better.

    P.S. I’m not a full time Rails developer. Almost all of my work is in ASP.NET MVC.

  42. I think a lot of this is totally overreacting to a problem most people don’t really have. Sure you may have to build custom authentication and logging and configuration etc…. but if you built this stuff correctly the first time you ‘ll be reusing it on your next project. I take that any day over some half-assed implementation that comes ‘in the box’.

    While you might ‘waste’ a couple hours setting things up for the first time in a project, what does that really translate to in the lifetime of a typical project? Not much I’d argue unless it’s a trivial project in which case the built-in stuff is probably fine.

    We’re software developers – we’re supposed to build stuff that interfaces with our customer’s business problems and not make their business problems fit around the framework we’re using.

  43. @Rick Strahl I agree alot with you. Microsoft especially this past year has given us some of the best tools ever, even if some of the old parts we all replace with lots of good community and MSDN resources.

    I also know there is alot of merit to what @Justin Etheredge had to say. I do feel that most of what he said has finally been delivered in a readily feasible and open manner to us with ASP.NET 4, MVC3, Nuget and the MVC Scaffholding package (really as a reference template).

    I’m looking forward to see what people come up with and publish with Nuget. I see that we will get alot of the benefits the rails community has, but maybe even with more choices. Especially since people have for years built their notions of how to best work with the ASP.NET pieces they replace, like Membership. Nuget is a brand new day in the ability to create easily accessible software with .NET that wants to be shared and used.

    I’ve also seen what people like Rob Conery have done, something as simple as packaging Massive as just a raw .cs file. This blends in more of the advantages of dynamic languages so easily into .NET by making a project implicit to extend. I guess also ironically it showcases more of what power .NET has in being able to work with dynamics in sane fashions to lower lines of code, especially boiler plate code usage.

  44. I think Josh’s post here on Microsoft working “with” the OSS community to create those defaults is possibly a way forward.


    I think one of the biggest frustrations of the .NET community as a whole is it is fragmented into 2 groups. The 9-5 “enterprise” developers and everyone else. Microsoft tries to build frameworks for both camps an inevitably ends up disappointing both.

    If Microsoft allowed community involvement into the frameworks they build everyone could benefit.

  45. Quote Travis

    “I think one of the biggest frustrations of the .NET community as a whole is it is fragmented into 2 groups. The 9-5 “enterprise” developers and everyone else. Microsoft tries to build frameworks for both camps an inevitably ends up disappointing both.”

    Well said :) I’m sure this is gross generalizing .. but I too feel the same way.

  46. This is not a binary choice or an evaluation of one framework is better than another.

    Both have strength and weaknesses and to actually know both frameworks and others will serve you better in the long run.

    ASP.NET MVC has borrowed heavily from rails. It is always beneficial to step outside your comfort zone and explore new languages and frameworks.

    Trying to prove one is better than the other is futile.

  47. Tyler Mercier

    @Rick Strahl You see nothing wrong with developers everywhere, solving the same problems over and over? That sounds like a major waste of effort to me. Why not take a solution someone else spent a lot of time coming up with?

    @Justin, great post. Really like the discussion this stirred up. Keep up the good work and getting us MS devs to challenge what we have taken for granted. Perhaps a few blinders will come off :)

  48. Adrian Edwards

    Don’t you think that WebMatrix is a step towards an opinionated full-stack solution like the one you describe?

  49. I am a long time web form (/w 3rd party ajax) developer. Recently I wanted to learn MVC framework, having played around with it (not long) and also tried Rails… it really amazed me how rails can be so intuitive. Now I really want to pick up on Rails but most applications in my firm are .net based. It would be difficult to convince anyone to jump onto the Rails bandwagon. Its a shame though, I am now reluctant to go further with .net MVC.

Leave a Reply

Your email address will not be published. Required fields are marked *