HornGet.net

Just a short post to give a belated shout out to the HornGet Project. This project grabs the latest source code from popular .Net openimage source projects such as Nhibernate and Ninject etc. compiles it and produces nice up to date assemblies.

The great thing about this project it that it provides a one stop shop for quickly grabbing all the assembles you need for a new project without having to go to 3-4 different sites, grab the source and build it yourself.

So next time you need an up to date toolset, check out www.hornget.net and save yourself some time

Posted by The Admin on Monday, January 04 2010

NUnit test method Live template for Resharper

Just a quick post, If you follow a TDD approach in your development this little live template is invaluable. I name my tests using the a technique from Roy Osherove’s excellent Art of Unit Testing Book. I think this makes it easy to get the gist of the test at a glance.

 

If you were writing a calculator with a add method that return the sum of two numbers the test method would be:

Add_TwoIntegers_ReturnSum()

Not very ground breaking but when you have lots and lots of tests it helps identify the test’s purpose that little bit quicker.

As a aside, one of the two quickest productivity gains you can make is to learn as many code snippets in Visual studio as possible and create custom ones for other tasks you do repeatedly. The second is to get a copy of Resharper, and really learn all of the many great thing it can do!

Posted by The Admin on Friday, December 11 2009

Install windows 7 from USB in two clicks using UNetBootin

If you tried the beta or you have a MSDN or TechNet Subscription you will have access to ISO images of Windows 7 to install and try out. If however you want to save on the blank DVD’s or you want to install it faster, you can choose to use a USB and install it from there.

There is already lots of pages on the web where you will find instructions about formatting and partitioning your USB drive, using the command line diskpart tool  and then installing the Win7 boot loader to make it bootable. I did this method a couple of times and it works great, but there is unetbootin startupa easier method!

Introducing UNetBootin

UNetbootin is originally an open source tool to help Linux users install distros with out having to burn to disk, it comes with a Windows or Linux version of the tool. As UNetbootin comes from the Linux open source world it has a bunch of presets for popular Linux distros and live CD’s.

However it also allows you to give it any ISO image file to create a bootable USB drive.

Using UNetBootin with a windows 7 ISO

This is a really straight forward process, simply have a USB stick that has enough space for the image and is formatted with the NTFS file system.

For a windows ISO you simply ignore the Preset distribution options, and click the DiskImage option and then point it to your ISO file.image

Once you’ve done this, simply make sure that the correct drive letter is set for your USB drive and click ok.

UNetBootin will then copy all the file and install the boot loader onto your USB drive. The process takes about 15 minutes or so depending on the size of the ISO.

Once it’s done, just put the USB drive in the computer you want to install on and boot from USB.

I’ve since tried this with a number of different ISO images at work and confirm it works with Windows server 2003/2008 and XP ISO’s too.

Download UNetBootin Here.

Posted by The Admin on Wednesday, December 09 2009

Wall outlet with built in USB sockets

imageI Think that this is a great idea, I dream of the day this is standard for your home/office.

Just think of all the adapters you have to carry around with your phone or mp3 player etc. Many devices like the iphone/ipod already let you charge from the USB socket in your PC. If only device manufacturers standardized on MiniUSB, then you would only need to carry one cable for all your devices!

Available at Fastmac.com

Posted by The Admin on Monday, December 07 2009

Using Ninject 2.0 beta and ASP.MVC

Last weekend I watched two great talks about ASP.net MVC by Steve Sanderson and Sebastian Lambla at Developer Day Scotland. One of the main points I got from both talks was the benefits of a IOC container in you MVC projects. So I decided to try out an IOC container for myself :) I kept hearing good things about Ninject on Twitter and various blogs I read, so I decided to take the plunge with Ninject.

Quick note - I’m going to write about using Ninject 2.0 beta which is hosted on GitHub, and not the 1.5 version which is the current release that is linked on their website. Don’t make the mistake I did and grab the wrong version, doh! If you skip to the bottom of the post you can also see where I've posted my global.ascx file used in the project in it’s entirety.

Downloading and building the 2.0 beta source

The first step in getting Ninject up and running is to grab the source and build the latest version. Ninject is currently hosted on GitHub: http://github.com/enkari/ninject/tree/master 

Github also hosts the Ninject ASP.MVC extension that makes it easier for us to integrate Ninject into our MVC project so you’ll want to grab that as well. Once you’ve downloaded both simply run their respective build scripts to produce the Ninject assemblies.

Adding Ninject to your project

Now you need to copy the Ninject.dll and Ninject.Web.Mvc.dll files to your project, I store all the external assemblies for my project in a folder called ‘libs’ however where you place them is up to you. Where ever you do place them you need to add references to both these assemblies in your project:

image image

 

Setting up MVC to use Ninject

Most of the configuration of Ninject takes place in your projects Global.asax file. The first step is to change the MvcAppplicaton class to inherit from NinjectHttpApplication instead of System.Web.HttpApplication like so:

public class MvcApplication : NinjectHttpApplication 


NinjectHttpApplication contains it’s own implementation of the Application_Start() method which helps to initialize the Ninject Kernel. It also setups up your project to use the Ninject Controller Factory allowing you to use Dependency Injection for your controllers.

Because Ninject uses its own Application_Start() method, it provides you with a new method called OnApplicationStarted(), which you override, that you can use in its place:

protected override void OnApplicationStarted()
  {

   RegisterAllControllersIn(Assembly.GetExecutingAssembly());

   RegisterRoutes(RouteTable.Routes);
}

In the code above I’ve simply moved the RegisterRoutes methods into OnApplicationStarted(),  the first line tells Ninject to register all the controllers in our MVC Assembly in our Ninject Kernel.

Next we implement Ninject’s CreateKernel() method to initialize our kernel and tell it the bindings that we want Ninject to handle:

protected override IKernel CreateKernel()
  {
   var kernel = new StandardKernel();
   kernel.Load(Assembly.GetExecutingAssembly());
   return kernel;
  }


The first line creates the kernel and then in the second line we are telling it to search our projects assembly to look for any Bindings that we have created.

Creating bindings for Ninject

To create bindings for your container you simply create a new class file and inherit from the NinjectModule class:

public class WebModule : NinjectModule
 {
  public override void Load()
  {
   Bind<IRepositiory<Job>>().To<JobsRepositiory>();
  }
 }


For each module we override the Load() method and provide our bindings, You can find out more about Ninject Modules & Bindings on the Ninject Wiki

Conclusion

I hope you’ve found this useful, I’ve only being playing with Ninject for the last couple of days but so far I'm impressed, once you get it up and running it’s really easy to add new bindings and start to build your application in a more test friendly & loosely coupled manner. Ninject is also seriously lightweight – the two assemblies are only 98kb combined :)

Full Global.ascx listing:

public class MvcApplication : NinjectHttpApplication 
    {
  protected void RegisterRoutes(RouteCollection routes)
  {
   routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

   routes.MapRoute(
    "Default",                                              // Route name
    "{controller}/{action}/{id}",                           // URL with parameters
    new
    {
     controller = "Home",
     action = "Index",
     id = ""
    }  // Parameter defaults
   );

  }

  protected override void OnApplicationStarted()
  {

   RegisterAllControllersIn(Assembly.GetExecutingAssembly());

   RegisterRoutes(RouteTable.Routes);

   
  }

  protected override IKernel CreateKernel()
  {
   var kernel = new StandardKernel();
   kernel.Load(Assembly.GetExecutingAssembly());
   return kernel;
  }
 }

Posted by The Admin on Friday, May 08 2009

First Post

 Hi, Welcome to the first post of my blog. Hopefully in the next few days I'll have more intresting stuff here.

Posted by The Admin on Friday, March 20 2009