3

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?

amhed
  • 3,649
  • 2
  • 31
  • 56
  • 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 Aug 13 '12 at 07:05
  • 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 Aug 13 '12 at 14:21
  • Seen this? http://stackoverflow.com/questions/4358395/mvc3-ninject-how-to "When using the MVC extension you have to use OnApplicationStarted instead of Application_Start." – timothyclifford Aug 14 '12 at 01:12
  • 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 Aug 14 '12 at 21:31

1 Answers1

1

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!

amhed
  • 3,649
  • 2
  • 31
  • 56
  • Can you provide the setup of the code. I am having the same issue, but cant get it to work. I used aso Nuget to install. For instance where do you get the NinjectResolver? – Mounhim May 17 '13 at 10:22
  • @Mounhim we stopped using umbraco alongside with our app. We had too much overhead on the project. At the end we decided to run the CMS project on another subdomain and share the same session using Cookies/Forms Authentication. Also, I think that after Umbraco 4.10 they implement their own IoC Container and you can't implement your own :S – amhed May 17 '13 at 12:52
  • Thank you for your answer. However I believe they have mention that one can implement IoC of choice. I will look further – Mounhim May 17 '13 at 17:36