“没有为此对象定义无参数构造函数”当将 MVC3 与 Ninject 结合使用时
首先,这是代码:
NinjectControllerFactory 构造函数中绑定
class MrBigglesworthServices : NinjectModule
{
public override void Load()
{
Bind<IAuthenticationRepository>()
.To<AuthenticationRepository>()
.WithConstructorArgument("connectionString",
ConfigurationManager.ConnectionStrings["VoiceDB"].ConnectionString
);
Bind<IAppRepository>()
.To<AppRepository>()
.WithConstructorArgument("connectionString",
ConfigurationManager.ConnectionStrings["SessionStore"].ConnectionString
);
}
}
在搜索控制器的
private IAppRepository appRepository;
public SearchController(IAppRepository appRepository)
{
this.appRepository = appRepository;
}
:根据我在在线示例中看到的内容,这应该足够了,但由于某种原因,它引发了上述错误。有什么建议吗?请并谢谢你。
First off, here's the code:
Binding in the NinjectControllerFactory
class MrBigglesworthServices : NinjectModule
{
public override void Load()
{
Bind<IAuthenticationRepository>()
.To<AuthenticationRepository>()
.WithConstructorArgument("connectionString",
ConfigurationManager.ConnectionStrings["VoiceDB"].ConnectionString
);
Bind<IAppRepository>()
.To<AppRepository>()
.WithConstructorArgument("connectionString",
ConfigurationManager.ConnectionStrings["SessionStore"].ConnectionString
);
}
}
Constructor for the Search Controller:
private IAppRepository appRepository;
public SearchController(IAppRepository appRepository)
{
this.appRepository = appRepository;
}
Based on what I've seen with online examples, this should be enough, but for some reason, it's bringing up the error mentioned above. Any suggestions? Please and thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为您提到使用
NinjectControllerFactory
我认为您使用了不正确的实现。考虑切换到 https://github.com/ninject/ninject.web.mvc /wiki/MVC3 代替。这是 Ninject 和 MVC3 广泛使用的集成。Because you mention using a
NinjectControllerFactory
I think you are using an incorrect implementation. Consider to switch to https://github.com/ninject/ninject.web.mvc/wiki/MVC3 instead. This is a widely used integration of Ninject and MVC3.