我最近关注了Aaron Powell关于使用Umbraco4支持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中设置了一个使用web激活器附加到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在这种情况下工作?
发布于 2012-08-16 02:53:30
我们从头开始。使用Umbraco编译的二进制文件/网站,而不是源代码。从那时起,我们使用nuGet安装了MVC4和Ninject,一切似乎都很正常。
感谢那些不管怎样帮助我们的人!
https://stackoverflow.com/questions/11926531
复制相似问题