Apostol Apostolov

Practical thoughts about software

NHibernate is a gun

What do I mean by that? Well let me give you some history.

A While back I worked on a big enterprise platform/project where we did not have much experience using NHibernate. I was learning it in the process of writing the code and for the framework and everything looked peachy. I even sometimes found ways to optimize my code to make it 10+ times faster. Like having a session-per-request so the I wouldn’t open a transaction every time I make a query to the database(if you don’t know – transactions – very expensive).

One of the problems I think now was the notion that we were not creating an application but a platform, and then we were going to make applications on top of it. So we worked a couple of months without a client and then we began making a project for a client but we decided to ship it when it was fully ready. So for a long time we had no real input of how the system was working(we had no info if it’s slow or fast or if it had production problems).

Naturally I became a fan of Ayende because of all the awesome features of NHibernate that he posted in his blog and that were buried deep down in the NHibernate code.

Then one day I found Ayende’s NHibernate Profiler. If you don’t know what it is – it’s an application that connects to NHibernate’s logs and analyzes them. It shows you common and not so common pitfalls you have in your application. If you’re using NHibernate and not using NHibernate profiler – you’re doing it wrong.

So when I ran NHibernate profiler I was Like WOW! I was astonished by the number of problems we had in the application. SELECT N+1, not using paging almost everywhere etc.

So what was the real problem in this situation? We worked with objects. We didn’t know or didn’t gave a real thought about what really happens underneath NHibernate. How the queries are made and what happens in the DB with those queries. We didn’t give a thought about the data access. After all – we have abstracted it away, haven’t we?

I left that company a while back and now I’m not using NHibernate that much(because the infrastructure in the company I work for is not using NHibernate not that I don’t like it - I think it’s awesome actually). I had forgot about this story until I saw the recent announcement of Umbraco’s decision to stop the development of their new version of the CMS. At first I didn’t quite understand why they did this. They said something about their architecture being flawed on the Keynote event in which they announced their decision. They said also that the development team’s lack of experience with NHibernate was the part of the problem and that they shouldn't have made the new version ‘in the dark’ - away from the community(away from the customers). After that I read the review Ayende did on Umbraco’s new version. And guess what? It was like a Daja Vu. Yea maybe the business was different and the applications were different and the logics and teams and decisions were different but the root cause was the same. They didn’t thought about the data access.

And now we get to the point of this article. NHibernate is a gun. It gives you power and freedom to do all kinds of things. So if you see it for the first time or/and don’t know how to use it – you could easily  point it in the wrong direction – like to your head – and you can shoot yourself with it. But if you know what NHibernate is and what it does and know what you’re doing and use it right. It will keep you safe and sound from the dangers of the jungle.

Custom domain to Windows Azure website

Disclaimer: The information in this post is a little outdated. Check out the more up-to-date information about configuring Windows Azure Websites with Domain.

Some time ago Windows Azure team posted a new 'version' to the the service.  I was and still am very thrilled about the new features they put in there. I like  the new interface very much and just love the TFS and GIT automatic deployments. Like the Azure team knew what would make the developers happy and more productive and they put it in there.

Naturally I began porting one of my sites(applications) on Windows Azure. I followed the procedure as it was described in the very detailed tutorials. If you haven’t tried it you should. It so natural and easy to use that I makes a big smile on your face.

Then I decided to point my domain to the Windows Azure website. So I searched the web to find some info and there was a good explanation in Azure’s blog. Now let me say – I’m not very good with managing domains etc.  Just a little less than a year ago I bought my first domain and made some tests with it. Never used it much as a whole.

And here was my first disappointment – we CAN point a domain to our hosted sited but only if they’re on a RESERVED instance. It seems that shared instances cannot have a custom domain.  It’s  good that the Azure team wants to fix that and will implement CNAME for shared instances in the future though. Hooray!

So next thing for me was to try switching to reserved mode and trying to attach the domain to a CNAME.  Following the explanation on Azure’s blog  – I made a CNAME configuration on my domain provider. I attached to apostol-apostolov.azurewebsites.net – the app that I was testing the domains with. Then I made so all the subdomains redirect to ‘www’ and I made  ‘www’ to be a CNAME pointing to apostol-apostolov.azurewebsites.net . The configuration looked like that:


And then I typed my www.apostol-apostolov.com and  - well, I hit a wall.


So now what? I searched a little bit but every article out there had the explanation – make a reserved instance and point the domain with CNAME to the server alias and that is all. Maybe because I have little experience with domains I don’t know what I’m missing.

Finally after I was poking around a couple of hours I figured it out.


You have to add the domain you’re pointing to the list of hostnames of your website. And voila! You have a fully functional site with domain in the new Windows Azure.

Now I’m thinking of making a little test  for a week or two on “how much will the reserved instance cost me”. And “how much will Windows Azure make my life easier on a daily basis”.


Published at

Originally posted at