3
votes

I recently followed Aaron Powell's posts on supporting MVC controllers with Umbraco 4: http://www.aaron-powell.com/umbraco/using-mvc-in-umbraco-4 and http://www.aaron-powell.com/umbraco/using-mvc-in-umbraco-4-revisited

Everything works as expected. I can set up controllers and they work seamlessly well along side umbraco's pages. The thing is I'm trying to setup IoC with Ninject and haven't been able to get it working.

I've setup a class in App_Start that uses web activator to attach to the PreApplicationStartMethod and defined my kernel configuration as I have always had in the past:

 private static IKernel CreateKernel()
    {
        var kernel = new StandardKernel();

        //Standard Modules
        kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
        kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
        kernel.Bind<IUnitOfWork>().To<UnitOfWork>().InRequestScope();
        kernel.Bind<IConfigurationManager>().To<ConfigurationManagerWrapper>().InRequestScope();

        //Security
        kernel.Bind<ISecurity>().To<Security>().InSingletonScope();
        kernel.Bind<IMembershipAuthorization>().To<MembershipAuthorization>();
        kernel.Bind<IFormsAuthorization>().To<FormsAuthorization>();

        //Registering my services, repositories, and connections
        RegisterRepositories(kernel);
        RegisterServices(kernel);
        RegisterConnections(kernel);

        GlobalConfiguration.Configuration.DependencyResolver = new NinjectResolver(kernel);

        return kernel;
    }

I've debugged the solution and this code gets run. But everytime I call a controller the injection isn't made and I get the "No parameterless constructor is defined" error.

Does anyone know how to get IoC working in this scenario?

1
Some obvious questions: Have you tried defining a parameterless constructor? And have you property bound the type you are trying to inject into the controller? - timothyclifford
Yes, parameterless constructors work fine. And yes, the property I'm trying to inject is bound in the RegisterRepositories method that i pasted above. - amhed
Seen this? stackoverflow.com/questions/4358395/mvc3-ninject-how-to "When using the MVC extension you have to use OnApplicationStarted instead of Application_Start." - timothyclifford
I'm not even using global.asax, I'm using web activator and the PreApplicationStartMethod hook. The method runs correctly, that's the weird part about it. - amhed

1 Answers

1
votes

We started from scratch. Using the Umbraco compiled binaries/website instead of the sources. From that point we installed MVC4 and Ninject using nuGet and everything seems to work fine.

Thanks to those who helped anyways!