Minq and Autofac – quick setup guide

Its really simple to get these setup together. Once you have your Sitecore MVC project up and running:

  1. Install Autofac from Nuget
  2. Install Autofac ASP.NET MVC 5 Integration (note, select the appropriate version you require)
  3. Create a new intializer class (see below)
  4. Update the AssemblyInfo and add: [assembly: PreApplicationStartMethod(
    typeof(###.Initialization.Initializer), “Initialize”)]

    1. See http://haacked.com/archive/2010/05/16/three-hidden-extensibility-gems-in-asp-net-4.aspx/ for more info on this approach. It avoids needing to update global.asax. This tip was taken from http://www.jasonbert.com/2013/11/03/tip-move-your-ioc-from-global-asax/
  5. Update the config as per https://github.com/tcuk/minq/wiki/MVC-Configuration
  6. Enjoy DI into your controllers

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">