Presenting at Brisbane Alt.Net December Meeting

Monday, November 30 2009         1 Comment

The final Brisbane Alt.Net meetup for the year is this Thursday, the 3rd of December. I’ll be presenting on bootstrapping NHibernate with MVC and IoC and whatever discussion follows on from there.

If you’d like to come along, it would be good to put some faces to names, you can RSVP at the eventbrite page.

NHibernate, MVC and Ninject

Monday, November 16 2009         4 Comments

A few weeks back I blogged about my lightning talk on bootstrapping NHibernate with StructureMap inside an ASP.NET MVC project.

Since then I finally made some time to play around with Ninject, which seems to be the most popular IoC container amongst my Readify peers these days. Ninject is very nice to use, and very simple to get started with and of course I thought about it in the context of my NHibernate sample and whether replacing StructureMap with Ninject would make for another good sample.

Note : The code here is based on the 1.0 release of Ninject, I’m sure some funkier stuff is coming in the 2.0 release.

StructureMap has a very powerful Fluent API for controlling the instancing and construction of requested types. It let me do some funky things for building an NHibernate SessionFactory and opening a new Session.

ForRequestedType<ISessionFactory>()
	.CacheBy(InstanceScope.Singleton)
	.TheDefault.Is.ConstructedBy(() => new NHibernateSessionFactory().GetSessionFactory());

ForRequestedType<ISession>()
	.CacheBy(InstanceScope.Hybrid)
	.TheDefault.Is.ConstructedBy(x => x.GetInstance<ISessionFactory>().OpenSession());



Ninject applies a different model to StructureMap by keeping the API simpler, but allowing you to plug in custom classes to control your activation.

To achieve the same task in Ninject, I’ve created a a Module for my NHibernate configuration.

I’ve specified that the ISessionFactory and ISession types be constructed by their own Providers.

public class NHibernateModule : StandardModule
{
	public override void Load()
	{
		Bind<ISessionFactory>().ToProvider(new SessionFactoryProvider()).Using<SingletonBehavior>();
		Bind<ISession>().ToProvider(new SessionProvider()).Using<OnePerRequestBehavior>();

	}
}

public class SessionProvider : SimpleProvider<ISession>
{
	protected override ISession CreateInstance(IContext context)
	{
		var sessionFactory = context.Kernel.Get<ISessionFactory>();
		return sessionFactory.OpenSession();
	}
}

public class SessionFactoryProvider : SimpleProvider<ISessionFactory>
{
	protected override ISessionFactory CreateInstance(IContext context)
	{
		var sessionFactory = new NHibernateSessionFactory();
		return sessionFactory.GetSessionFactory();
	}
}



And you’ll see I can specify that the SessionFactory has a SingletonBehavior as it’s expensive to set up, but threadsafe and designed to be a singleton.

In the sample I’ve also added a ServiceLocator. When using StructureMap if you don’t mind coupling your code to StructureMap (probably not the best idea) you can can configure your container in one place, then make calls to ObjectFactory anywhere you need to. The Ninject kernel doesn’t work this way, so we need to keep a reference to a configured kernel in a place that can be accessed by the code. Nate Kohari, the author on Ninject provides a good example of the Service Locator pattern with Ninject on his blog.

Other than those two changes, the Ninject sample is the same as the StructureMap one, you can download it here and see for yourself.

 

Moving to Brisbane

Tuesday, November 03 2009         3 Comments

I’ve lived in Sydney most of my life. I spent my childhood here, moved away to near Bathurst when I was 9, went north and lived near Lismore and Byron Bay for uni when I was 18, but as soon as I was able I came straight back to Sydney. The Inner West of Sydney (Erskineville, Newtown, Leichhardt, Petersham) has been home for many years.

However, with two small kids and the increasing price of housing in Sydney, we’ve started to feel a little cramped. We’d had some discussions about moving out of the city, possibly north again “in a few years” but no firm plans.

So recently, in a conversation about hiring people at Readify, and how we were in need of people in Brisbane something clicked. At first I dismissed it, but it stuck in my mind. Why not move to Brisbane ? I’ve got good friends there, I have two brothers there, and it could just be the change of scenery we need.

As quickly as the decision was made, things got underway. On Saturday, after a long drive, I arrived in Brisbane. Living temporarily in the city at the moment, but we’ve started the hunt for a nice big Queenslander to live in.

It’s going to be hard leaving so many good friends in Sydney, but most of them are only ever an IM, email or a tweet away anyway. I’m also going to miss King St Newtown, but I’m sure I can find reasons to come back and visit.

I’m very much looking forward to becoming a part of the tech community here, first stop is the ALT.NET Beers on Thursday.

Migrating Graffiti CMS from VistaDB to SQL Server

Monday, October 26 2009         3 Comments

I’ve been running this site on Graffiti CMS for a while now. Graffiti seemed like such a good product, it’s a shame Telligent seem have to abandoned it without any communication.

Anyway, after a long hiatus I started to actually use it again, and found every second or third page view would hang or throw errors, comments didn’t get indexed properly and just weird behaviour was being exhibited. Inside the admin control panel, log viewers were showing totally empty as were viewing statistics.

After some investigation it looked as if the VistaDB I was running with may have been the culprit, and looking around it seems like a few other people hit the same limits.

The instructions at Al Pascual’s blog were good. Create a new Graffiti DB inside SQL Server, then use the supplied migration tool to copy the data over. Unfortunately, it appeared that my VistaDB database was corrupt and had some duplicate primary key data in there, causing the whole thing to crash.

Next step was looking into a way to open up the VistaDB file, I went to their site and downloaded a trial. Of course, they are up to version 4 now which won’t play nice with my v3 file. There doesn’t seem to be a way to download older version from their site either. Thankfully I found a version 3 trial at download.com.

The VistaDB tools have a Repair Database function, which seemed to just time out or hang with this database.

I decided to delete the tables most likely to be the culprits, the log table which Graffiti is meant to prune automatically but somehow had over 4 million rows, and the pageview statistics page. Deleting all rows from those tables left the statistics table with 6 rows of all NULL values in it, and the log table still reporting over 4 million rows.

Thankfully though, after these two steps I could repair the database and bring it down to a nice small size.

Once the database was repaired I could run the Graffiti migration tool and move it into a fresh SQL Server database, and push that to my webhost.

So I’m all good now, hopefully I won’t have too many problems. I’ve lost some statistics, but I’m tracking those in Google Analytics anyway.

Lessons learned, don’t keep your data in a format you can’t work with, especially when the vendor is likely to upgrade to an incompatible format and pull their tools out of circulation.

It’s still a shame that Graffiti is abandoned, hopefully the people at Telligent will get it together soon and either follow through on their announcements of future development, or listen to their community forums and open source it. It could be a nice platform and a good developer ecosystem if it looked like it had a future.

NHibernate made easy with StructureMap and Fluent NHibernate

Sunday, October 25 2009         1 Comment

A while back I presented a 10 minute lightning talk at the Sydney Alt.Net group on making NHibernate easier with Fluent NHibernate and StructureMap in the context of an ASP.NET MVC app.

I set about putting this together as I've found a large interest in NHibernate from other developers, but there seems to be a bit of a barrier to entry when it comes to the configuration, mapping and patterns around session lifetime. None of these are really hard, but taken on at once can be a mental hurdle.

StructureMap is similar, for most scenarios a simple tool to use, but the number of options for configuring it can turn people away when looking at the documentation.

The premise of my short talk was that using Fluent NHibernate to configure and map NHibernate, and StructureMap to manage the SessionFactory and Session lifetimes makes it an easy stack to work with. Using this in the context of ASP.NET MVC allows you to inject your data access code very easily into your controllers, giving you a nice, loosely coupled architecture.

I’ve been sitting on this post for a little while (so long in fact, that I'm not the first person to blog about it) because I wasn't sure of the best way to document it. In the end I decided that posting the solution, and adding lots of comments was probably the easiest, because you can step through the code inside VS.NET.

So download it here and have a look. Start at the Global.asax.cs and navigate your way through the code from there. If you’d like to run it, there’s a database creation script there, you’ll need to change the connection string inside Web.config.

Bear in mind, this is NOT thorough documentation for NHibernate or Fluent NHibernate. There are a few best practice type things I’ve left out for the sake of simplicity. For starters there’s no error handling or transaction management, and if you want to use NHibernate seriously you need to understand why you map things the way you do, and what N+1 means. What I did try to achieve was demonstrate that the “ugly” initial parts of NHibernate can be made very simple with a little bit of help from a good IoC container and Fluent NHibernate.

Any feedback would be welcome, I am interested in building this out into a bigger sample so I’m open to ideas.

The Pomodoro Technique - Staying focussed

Saturday, October 24 2009         6 Comments

I’ve been working at home by myself for a few weeks, it’s mostly going well but some days I’m really easily distracted and not as productive as I want to be. As a result, I get unhappy about my days output, which makes me more easily distracted the next day... it’s a vicious cycle. 

Anyway, recently while on another engagement, a colleague told me about the Pomodoro technique. Essentially you use a timer to do 25 minute blocks of work where you turn off all interruptions like IM / Email / Twitter, when the timer goes off you give yourself a 5 minute break. Every 4 “pomodoros” you give yourself a longer break. The idea is that 25 minutes gives you enough of that sense of urgency your mind has when under a deadline while giving you a reprieve from it. 

Done properly it’s a lot like a mini Scrum. You commit to what you want to do in your 25 minutes, at the end of that look back at the work and decide what you need to move to the next one.

Then you keep track of how long standard tasks take you, what your interruptions are and how you can work with them. 

My first day I spent most of today working with the basics, 25 minutes head down and focussed, then 5 minutes to check email, get a drink etc and I got a lot more achieved that day than I did week.

I fell off the wagon with it after a couple of disrupted days with meetings in them, but came back to it this week, and once again found it to be a massive productivity boost. 

I found it very helpful to write down a list of all the things I could think of that needed doing, and adding to that list when I thought of something I wanted to do. Once again, this seemed a lot like a Scrum product backlog, and I found that some of the things I’d usually drop what I was doing to look into never really got important enough to include into one of my blocks of work. 

There’s a web site and free ebook at the official site, and a nice timer app called Focus Booster that I’ve been using.

Hope it’s helpful to someone else, as someone who often struggles maintaining focus on some of the less interesting tasks I’m finding it to be a great technique.

Alt.NET and the culture of negativity

Sunday, May 10 2009         4 Comments

An interesting lesson I've learnt over the last year is when you find yourself violently disagreeing with someone, or worse still, going along with an angry mob who violently disagree with someone, instead of ignoring that person, or trying to find fault, pay extra close attention to what they have to say.

It's an interesting experiment. You might still come away violently disagreeing, you'll probably come away still disagreeing with most of what they have to say, but I'll bet you that if you truly try to understand where they are coming from, you'll find yourself challenging your assumptions and just possibly learning something.

Every community needs a bad guy, for most of the Alt.NET folks, that bad guy is Scott Bellware. He's an easy target if you want to stand in the crowd and throw stones. But if you pay attention to the things he has to say, a recurring theme is that people have stopped using the Alt.NET label to learn, to teach and to help, and use it more as a platform of self promotion.

I'm finding this to be depressingly more true every day at the moment.

Alt.NET on one hand has given an umbrella with which to talk about a number of topics that didn't really have a good home not so long ago. These discussions have brought us a number of open source products and some fantastic resources for learning, not to mention brought local, face to face community to a group of developers that really didn't feel at home inside the usual run of the mill Microsoft developer user groups.

On the other side, there is an ever increasing group of vocal people in blogs, lists and Twitter who seem to be using the Alt.NET as a means for gaining notoriety by being openly negative about, well, pretty much everything that falls directly outside of the Alt.NET "stack".

There are examples all over the place, such as blog post attacks on Oxite and other MVC guidance attempts by Microsoft (not saying there wasn't justification for a lot of these comments, but there is a constructive way to act and there being childish), the latest blog storm on whether ASP.NET MVC is "worth learning" or not and daily twitter pursefights and general cliched sniping at anything that isn't deemed acceptable to Alt.NET dogma.

At this point it’s not really about Alt.NET and more about “look at me and how alternative I am”.

Some classic examples can be found in the comments to Rob Conery's recent blog post on what Microsoft should "do" for open source.

By the way, there is a fascinating comment there from James Peckham.

“I work in a financial institution. We have a great deal of heterogenous systems and database platforms. From c#, VB, MSSQL to oracle, vsamm files, and DB2. We have java, websphere, asp.net webservices, wcf, and a host of many different types of technologies all working together.

I've seen consistently that our microsoft technology based teams have more secure code, easier to maintain code, and put together more complexity on higher visibility applications more quickly than other teams.

We do have more outages than anyone else but usually they're caused by one of our java or mainframe dependencies. Rarely is our MSSQL a problem or any windows server have any problems. They're easy to update, patch, maintain and have considerable uptime. Our java apps have memory leaks, have considerable IO problems and security vulnerabilities that are constantly being unearthed.”

I've seen a lot in various companies to back this up too. Some of these companies even have *gasp* Enterprise Architects making decisions about how best to get this stuff to work together too.

This is Microsoft's bread and butter, in this world, open source anything is a hard sell, mainly due to legal paranoia. Microsoft releasing their own ORM, Testing framework, build platform, IoC container etc means that companies feel safe using them, and everyone wins. They would be foolish to ignore this market to pander to the desires of some random operator, who bought Eric Evans's book, applied a smattering of the repository pattern to one project and calls him self a DDD purist while cranking out content management sites for small websites.

Back to the Alt.NET thing though, if people really want to make a change in the developer world, then we must lead the way, teach and inspire. Remember that it's easier to catch flies with honey than vinegar. If your goal is to get some weird "respect" from a small group of insiders, then I'd suggest either re-evaluate that desire, or enjoy it while it lasts, because when the next new thing comes along all the bandwagon jumpers will all be there, probably sneering at Alt.NET.

On joining Readify

Tuesday, May 05 2009         No Comments

This post is a little late in coming, mainly because it seems every third post here is about me in a new job!

In November of last year I was chatting with Paul Stovell about what I was up to (nothing overly interesting) and he suggested I have a conversation with Readify. It didn’t seem like a bad option at the time and we did start talking. That conversation took a while, but the end result is that at the end of March I joined Readify as a senior consultant.

After my first week of induction things and some preparation for a client engagement, I’ve been pretty much head down working in the development team at one of our clients. It’s been quite a while since I was hands on with so much code, and it’s been an interesting experience. It’s quite amazing to be in the (oftentimes virtual) company of so many smart people.

I’ve not really carved out my little niche in the land of Readify yet, but give me some time, I have some ideas.

Of course, now I’ve said that I feel like I should go put some disclaimers on my blog. But it should be clear, anything I say here is my opinion only, and doesn’t necessarily reflect the views of my employer or any other entity (or even me sometimes, 10 minutes after I’ve posted it!).

Three wireless broadband and Windows 7

Monday, March 30 2009         5 Comments

Having just moved house I find myself in a position of having no reliable internet connection. Not my favourite place to be.

Last time I moved I had a prepay Optus 3G USB kit, the experience was unbelievably frustrating. I won’t elaborate here, but a #badoptus Twitter search will tell you in real time what people think about it.

Anyway, when the dust settled here today I pulled that modem out and it wouldn’t even think about connecting. Perhaps the SIM gets deactivated if you don’t connect for six months, I’m not sure. I certainly didn’t feel like spending any more money with them to find out.

I did notice the other day that Three are now doing a prepaid 3G offering with a BYO modem package as well. Looked like a good option so I picked one of those up. I have one of the ExpressCard modems from a few years ago so it should have been easy.

Should! Turns out my driver CD was damaged. 

I managed to get the Three SIM working with the Optus modem and connection client though. It worked OK but the USB modem is so easy to bump and I’m not sure it wasn’t half the problem while on Optus, so next step was to download drivers for the Express Card.

Note to Three here… your website sucks, and your search sucks. Your MobiLink download page is here, maybe someone could tell your search “engine”.

Downloaded those, do you think they would install for me on Windows 7 ? Of couse not. That’s alright, I didn’t want the silly connection manager anyway.

Next step, go to the source. The Three modem was actually a Novatel XU870, and the drivers can be downloaded by themselves here.

If you do this, you can actually set up your wireless connection like a dial up connection, and do away with any extra connection client.

It’s worth grabbing the documentation PDF from the Novatel page as it walks you through this process and you’ll need to configure the initialization string for the modem to make it connect. Once you can figure out the APN that is!

The APN is an access point name that informs the modem where to connect, much like a Wifi SSID. If you get this wrong, you’ll be trying to talk to the wrong access point and won’t get anywhere. Or something like that.

As usual, Google and Whirlpool to the rescue for things like this. It turns out that Three use a different APN for their prepay (“3services”) and their normal network (“3netaccess”). So the final init string for this is

AT+CGDCONT=1,"IP","3services"

So with the instructions followed, and the correct APN. I now can connect to the Three network, and I have internets once again while I wait for the ADSL to get connected.

Hopefully this combination of technolgies will seed the Google and help someone else in need.

UPDATE : Sept 09

It seems that on the RC (and I’m assuming RTM) of Windows 7, this configuration step is no longer needed. Just install the drivers, create a connection and away you go!

Tip : Speed up Firefox for ASP.NET development

Monday, February 16 2009         No Comments

Here's a tip for the ASP.NET developers out there using Firefox. Ever noticed how painfully slow FireFox is when you're using the ASP.NET development webserver that comes with Visual Studio ? Sometime last year I found a fix for this after a bunch of googling, then promptly forgot about it. I recently started developing on a new machine and was finding myself annoyed at the speed of Firefox and remembered this was something I'd dealt with in the past.

Take a look here for all the gory details, or if you're in a hurry, go into about:config in firefox, and set network.dns.ipv4OnlyDomains to localhost.

Now back to your (much faster) code.