Tuesday, August 28, 2012

GOTO 2012 - The Plus Side

I'm going to be GOTO again this year, and - as always - I'm excited about the program. Lots of exiting stuff going. While I will try not plan too much ahead, because I find it both more fun, and in the end also more educating to just go with the flow and see the talks that catch my attention when I'm right there at the conference, I have few things on my radar, that I'm most probably going to see:
  • Monday morning I'll likely kick off the conference with Brian Slettens Webs of Data talk. I saw Brian last year give a good technical talk on testing REST APIs, and the abstract for this one sounds intriguing.
  • Later monday I want to see Jonas Bonér talk about Akka - because Akka and Scala are so very, very cool!
  • Tuesday I want hear Sam Newman talk about how to design for rapid releases, because that's something I've been spending time thinking about too. It's a fascinating question really: How does the design of the software - of the code - effect the speed at which we can deliver. This is not just about how cruft slows us down, but also how to make software that we can build trust in quickly, which lends itself to automation and so on. I'm curious what Sam has to say.
  • Tuesday I also want to hear a little something about R. Mainly because I know nothing about R except that there seems to be a growing hype around it. And also languages are fun, so of course I need a language talk!
  • At the face of it Wednesday seems a bit slower for me, but I'll probably go see Dan Norths talk and Liz Keoghs talk, because both are such passionate, opinionated (in a good sense) and well spoken people.
You can see my (very) tentative schedule on this need thing GOTO made.

If you're going, create your schedule on the GOTO site, and post the link in the comments. I'd like see what caught your eye.

Friday, August 24, 2012

Draupner: Full Stack ASP.NET MVC Scaffolding

A little while back I announced on twitter that Mjølner had open sourced it's ASP.NET MVC scaffolding tool, Draupner:

Since then Draupner has been updated to produce ASP.NET MVC 4 apps, and all the dependencies have been updated too. So now since like a good time an introductory post about Draupner.

Why Did we Build Draupner?
Scaffolding is not a new concept. It's been used for while in other web frameworks, and moreover Steven Sandersons ASP.NET MVC scaffolding has been around for a while too. That begs the question why another scaffolder? Basically because the existing ASP.NET MVC one does not do what we (Mjølner) want the way we want it: We want a simple command line tool that can

  • Set up a new ASP.NET MVC solution with a "Web" project along with an associated "Core" project and a "Test" project.
  • Add further entities to the solution as needed throughout the solutions lifetime
  • Add CRUD operations and GUIs to existing entities
  • Add tests for all the other stuff it adds
  • Allow us to code away happily on the solution without having to think about making the scaffolding tool happy

Furthermore, and importantly, we wanted everything the tool produced to follow an architecture we've used successfully time and again. This means setting up a certain structure in terms of projects and folders, as well as building on a certain technology stack that we like to work with. In other words the tool, Draupner, is a set of practices we at Mjølner have had succes with put into code. These last bits are what sets Draupner apart.

What Technology Stack does Draupner Set Up?
Draupner projects uses a bunch of technologies, that we've found to work well together. All of them are set up as NuGet dependencies (except Rake). The stack includes:

You can see the full list on the Draupner page on Github.

What Does a Draupner Solution Look Like?
Let's have a quick glance at a solution built with Draupner. This screenshot shows which projects such a solution consists of:

The .Web project is the ASP.NET MVC site: It includes views and some thin controllers, that rather quickly call into the .Core project.

The .Core project is where the domain model goes and where the persistence of said domain model is handled. We like intelligent domain models, so this is where the smarts of the application is meant to go.

The .Test project contains xUnit tests for both the .Web and the .Core projects.

This is all set up by Draupner during the initial project creation. Moving on from there Draupner can add further entities to the domain model and add CRUD operations/GUIs to those enitites. Taking a look inside the .Core project we see:

This gives a peek into the technolgoy stack used by Draupner projects: Entities are persisted to a SQL Server database via NHibernate (you can reconfigure NHibernate all you want if you e.g. want to change to MySql), and the NHibernate mappings are set up with Fluent.NHibernate. Draupner also create repositories for the enities it creates which the the controllers in the .Web project can use.

Also notice the Castle.Windsor dependency: All the code produced by Draupner uses dependency injection and inversion of control.Caslte.Windows is the IoC/DI container of choice used by Draupner proejcts. E.g. the repositories mentioned above expect an IUnitOfWork into which it can enroll operations. This is injected into them by Windsor. Skipping ahead a bit let me mention that the .Web project sets up an NHibernate unit of work per web request and registers it with Windsor.

Lastly we can notice that Draupner sets up Log4Net, so that it's ready to go.

Let's move up the stack and open up the .Web project:

We can see that Draupner has created controllers for the enities it created. These each allow for simple CRUD operations.

Draupner has also created simple, but nice Ajaxy CRUD views for the entities. Neither of these are really expected to be used in production, but act as placeholders until "the real thing" is implemented.

Draupner has also created a few view models, which are used in the CRUD GUIs and has set up Automapper configurations to map between the view models and the enitites in .Core.

Worth mentioning is also that the .Web project uses Elmah for error logging in the web layer.

As mentioned Draupner creates tests for all this as well. They end up the .Test project:

The tests are xUnit tests and use AutoFixture and Rhino.Mocks.

So What Now?
If this caught you're interest go clone the Draunper sample project on Github and take a harder look at how things are set up or take Draupner for a spin, following the instructions in the readme. If you like it, but find something missing or not working let us know. We're not making any promises with regards to support and bug fixes though, so an even better idea is to send a pull request. Those we do welcome.