Umbraco 6 MVC and Dependency Injection

Thanks to some feedback on an Umbraco forum post I have re factored my code and made use of Dependency Injection.

I am using the awesome ninject and if you use the nuget package manager it is so easy its un real.

So navigate to https://www.nuget.org/packages/Ninject.MVC3/3.0.0.6 you can see the nuget install command Install-Package Ninject.MVC3 -Version 3.0.0.6 so install that into your web project.  This will pull down everything also in your app_start folder it will create a class NinjectWebCommon in there you have method


private static void RegisterServices(IKernel kernel)

{
kernel.Bind<ISearchService>().To<SearchService>()
}

You add your bindings there. Next update your surface controller mine looks like


private readonly ISearchService _searchService;
///
/// inject in this dependancy using ninject
///

///
public SearchFormSurfaceController(ISearchService searchService)
{
_searchService = searchService;
}

Its as easy as that. Now you too can be all hip and upto date with all the cool kids!!