This project is read-only.


Jan 19, 2010 at 10:10 AM

Hi guys

Just wondering how to wire up N2 CMS with this framework.

Specifically I can't quite work out how to wire up N2 using MEF.

I guess I need a class something like...


    [Export(typeof (IComponentRegistrar))]
    public class N2Registrar : IComponentRegistrar
        public void Register(IWindsorContainer container)

But to be honest I'm guessing at this a bit, and seem to be running into errors along the lines of

No component for supporting the service N2.Plugin.IPluginBootstrapper was found

How would you integrate N2 CMS into WhoCanHelpMe?

Thanks in advance



Jan 20, 2010 at 2:17 PM

Hi John, 

There's various aspects to integrating N2 into WCHM. N2 sits right at the top of the routing table, deciding whether the route is a content route, or a "normal" mvc route. Remember - the default routes of controller/action/id no longer apply as the url structure is now coming out of the CMS e.g.


In order to intialise the N2 engine and populate the N2 ContentRoute, you need to do something like this:



    public class RouteInitialiser : IComponentInitialiser
        /// <summary>
        /// Registers the routes into the routes collection
        /// </summary>
        public void Initialise()
            var engine = MvcEngine.Create();

            RouteTable.Routes.IgnoreRoute(" { *favicon }", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
            RouteTable.Routes.RouteExistingFiles = false;

            // Add the N2 CMS routes
            RouteTable.Routes.Add(new ContentRoute(engine));

            // Add the default route
                new { controller = "Home", action = "Index", id = string.Empty });


Ultimately, your not just initialising the engine, but populating the route table and registering the controllers for N2.

This should get you further on, but I'd recommend looking at the N2 MVC Templates example codebase for more info. Remember - the out-the-box HtmlHelpers are no good either - Html.ActionLink doesn't mean anything if N2 is handling your (dynamic) routing and url structure. Quite significant thinking/changes are needed when using a CMS in an application!


Hope this helps,



Jan 22, 2010 at 9:34 AM

Thanks for the response.

So I've played with this a bit and have managed to get N2 working with WhoCanHelpMe.

To ensure any existing controllers continue to work, you have to ensure that N2 doesn't take over your IOC Container completely, otherwise (I guess because both N2 and WCHM are using Castle Windsor) you find that your existing controllers error because their dependencies haven't been satisfied.

I ended up with this in Global.asax


 protected void Application_Start(object sender, EventArgs e)
            IWindsorContainer container = InitializeServiceLocator();

            var engine = MvcEngine.Create(new WindsorServiceContainer(container));


            _showCustomErrorPages = Convert.ToBoolean(ConfigurationManager.AppSettings["showCustomErrorPages"]);


And this in Route Initialisation


            // Add the N2 CMS routes
            RouteTable.Routes.Add(new ContentRoute(ServiceLocator.Current.GetInstance<IEngine>()));

Once you copy the relevant N2 assemblies and update web.config, you get an error message about the version of NHibernate (I believe the trunk version of N2 is using

To work around this I upgraded WCHM to use this version by updating the Referenced Assemblies and using a bindingRedirect 


    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <assemblyIdentity name="NHibernate"
                          culture="neutral" />
        <bindingRedirect oldVersion=""
                         newVersion="" />

This seems to be working quite nicely so far, with my existing controllers/spark views working as before, and any N2 content using the N2 engine.

The final step is simply to copy the N2 folder from N2's N2.Templates.Mvc project.

Thanks for the help




Jan 24, 2010 at 11:45 AM

Hi Jon,

Thanks for the update. I'm pretty familiar with N2 CMS - it was at the core of our original Fancy Dress Outfitters application, so we've been working with the N2 MVC bits since they were pretty much created. We decided to leave the CMS out of Who Can Help Me as we didn't want to over complicate things (and the app didnt really need it), however a few people have asked specifically about N2 and how we used it in the originial application.


So... I've spoken with the guys and we've decided it would be worth doing a proper branch of the application with N2 CMS integrated. I'm going to get started on this next week, and it shouldn't take me long as I've just started a new project at work and am going through this same process. I'll aim to have the Home and About pages served up from the N2 CMS whilst showing how we fitted the CMS into the overall architecture.




Jan 24, 2010 at 12:08 PM

Hi James

That sounds great, I'm sure it would help a lot of people who want to use N2 but aren't quite sure how to start.

Look forward to seeing what you come up with.

Thanks again