9x Your Nancyfx Boot Time With This One Simple Trick

I've always wanted to write a click bait headline and it seems like I've now found the perfect opportunity.

I run my side project, CompareVino, on the "Canoe" Appharbor plan - cheap and cheerful but it gets the job done. My only gripe was that NancyFX would take between 4 to 10 minutes to boot. This is bearable if it only happens when you release new code but really frustrating if AppHarbor decides to randomly reboot your website - which it does regularly - seemingly to balance resources on it's end.

In order to configure my own dependencies, I had overridden the ConfigureApplicationContainer method, made a call to the base method as outlined in this sample, and then set up the necessary dependencies my application relied on.

It turns out that the call to the base method was taking up 91% of the total boot time, or 8m 33s min, when deployed to AppHarbor. After reading through the documentation, the reason for this is that TinyIoC is helpfully scanning your assemblies and auto registering any dependencies it can find - part of the Super-Duper-Happy-Path motto behind NancyFX. While this is useful, it is also slow - painfully slow if you're running your app on low spec hardware.

If we take the on the (small) burden of registering our own dependencies, we can safely remove this call. In my application, the only additional registration I needed to add was a concrete implementation of IUserMapper, changing the method to look like this:

This one simple trick had the effect of reducing the time to configure the container to almost nothing and decreased the boot time of my application from 563 seconds to 52 seconds. Most importantly, however, I'm no longer receiving downtime alerts whenever AppHarbor reboots my website!

"This post was aggregated from http://jonleigh.me/9x-your-nancyfx-boot-time-with-this-one-simple-trick/ and all comments should be submitted on the original post"