4

I'm trying to use the default DD4T solution on Google code as a base for my DD4T project and am running into an error "No PageFactory configured"

First things first - I've had to create my own Provider module for Tridion 2013 SP1. I simply copied the DD4T.Providers.SDLTridion2013 project, renamed it, and then built it against the new versions of the CD DLLs.

I reset the supplied global.asax to inherit the standard HttpApplication class, and created the Kernel in the NinjectWebCommon.cs file in the App_Start folder of my MVC project (.NET 4.5)

My Application_Start() method in the Global.asax contains:

protected void Application_Start () {

            DependencyInjectionConfig.Configure();

            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }

and my nInjectWebCommon.cs file contains

 public static class DependencyInjectionConfig
    {
        public static IKernel Configure()
        {
            int publicationId = 0;
            if (!int.TryParse(ConfigurationManager.AppSettings["DD4T.PublicationId"], 
                                                                  out publicationId))
            {
                throw new ConfigurationErrorsException("Missing or invalid" 
                                    + " DD4T.PublicationId, please ensure" 
                                    + " this exists in the appSettings element"
                                    + " in your web.config and contains an integer value");
            }

            IKernel kernel = new StandardKernel(new DD4TNinjectModule(publicationId));
            BindServices(kernel);
            return kernel;
        }

        /// <summary>
        /// Bind your own services here
        /// </summary>
        private static void BindServices(IKernel kernel)                
        {

            // TODO: Inject services for your controllers
        }
    }

I've set the correct Provider, DD4T PubIDs etc, placed the CD DLLs, config and lib in my /bin folder.

I've set breakpoints in the DD4TNInjectModule.cs which shows the dependency code is executing, but the code always falls over in DD4T.Mvc.Controllers.TridionControllerBase.GetModelForPage(string PageID) where PageFactory is always null...

Am I missing something obvious here?

3
  • I've never used ninject, but looking at my dd4t apps, the 'PageController' is wired up to the mvc routes, this contains the creation of the 'PageFactory' and the logic in there. How is your proj configured for this set up?
    – johnwinter
    Commented Jan 20, 2014 at 19:08
  • exactly the same, the route handler works fine, but then it tries to resolve the PageFactory in the TridionControllerBase class which is always coming back as null, despite being set earlier in the lifecycle by the DD4TNinjectModule as part of the IKernel implementation.
    – mpaton
    Commented Jan 20, 2014 at 23:16
  • Would it be possible to share the code showing the wiring up of your dependencies in the NinjectModule? Commented Jan 21, 2014 at 11:59

3 Answers 3

6

Martin,

Sounds to me like your resolver isnt wired in to ASP.NET MVC - Ninject knows about your bindings but isn't being used to resolve anything yet.

Make sure you you register your resolver with ASP.NET MVC:

DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));

ASP.NET MVC will then use Ninject to resolve dependencies in your controller (and base controllers such as IPageFactory.

3

Siva is right, from what I've seen the tridion and provider assemblies have problems with the other dlls that they are referencing. This leads to the issue "it worked yesterday, but doesn't work now".

Regarding your particular problem, please have a look at my post (part B). I made it work finally, but it requires a lot of manual setup. Here is a link to a working DD4T project, to be used with a fresh MVC 5 application.

Hope that helps.

1
  • 1
    I'd like to suggest that you edit your post to replace the reference to "the guy above" to whoever it is you mean (was it Siva?) Answers can move up or down based on the voting, so "the guy above" today might be "the guy below" tomorrow. Commented Jan 22, 2014 at 21:08
0

I feel like Tridion DLL and Provider DLL versions are not in sink.

There is some mismatch with version, which cause this issue.

Update:

Try moving DependencyInjectionConfig.Configure(); to end of Application_Start()

protected void Application_Start() 
{
        AreaRegistration.RegisterAllAreas();

        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);

        DependencyInjectionConfig.Configure();
}
1
  • Thanks for the reply - my provider is built to the same libs end-to-end, so I'm (fairly) confident it's not that - also moving the DependencyInjectionConfig to the bottom of the method didn't make any difference unfortunately.
    – mpaton
    Commented Jan 20, 2014 at 23:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.