amhed
amhed

Reputation: 3659

Umbraco 4 + MVC + Ninject

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?

Upvotes: 3

Views: 886

Answers (1)

amhed
amhed

Reputation: 3659

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!

Upvotes: 1

Related Questions