3

我最近关注了 Aaron Powell 关于使用 Umbraco 4 支持 MVC 控制器的帖子: http ://www.aaron-powell.com/umbraco/using-mvc-in-umbraco-4和http://www.aaron-powell.com/ umbraco/using-mvc-in-umbraco-4-revisited

一切都按预期工作。我可以设置控制器,它们可以在 umbraco 的页面上无缝运行。问题是我正在尝试使用 Ninject 设置 IoC,但无法使其正常工作。

我在 App_Start 中设置了一个类,它使用网络激活器附加到 PreApplicationStartMethod 并定义了我过去一直使用的内核配置:

 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;
    }

我已经调试了解决方案,并且该代码开始运行。但是每次我调用控制器时,都不会进行注入,并且会出现“未定义无参数构造函数”错误。

有谁知道如何让 IoC 在这种情况下工作?

4

1 回答 1

1

我们从头开始。使用 Umbraco 编译的二进制文件/网站而不是源代码。从那时起,我们使用 nuGet 安装了 MVC4 和 Ninject,一切似乎都运行良好。

感谢那些无论如何帮助的人!

于 2012-08-15T18:53:29.527 回答