最近我切换到 Ninject 2.0 版本并开始收到以下错误:
Error occured: Error activating SomeController More than one matching bindings are available. Activation path: 1) Request for SomeController Suggestions: 1) Ensure that you have defined a binding for SomeController only once.
However, I'm unable to find certain reproduction path. Sometimes it occurs, sometimes it does not.
I'm using NinjectHttpApplication
for automatic controllers injection. Controllers are defined in separate assembly:
public class App : NinjectHttpApplication
{
protected override IKernel CreateKernel()
{
INinjectModule[] modules = new INinjectModule[] {
new MiscModule(),
new ProvidersModule(),
new RepositoryModule(),
new ServiceModule()
};
return new StandardKernel(modules);
}
protected override void OnApplicationStarted()
{
RegisterRoutes(RouteTable.Routes);
RegisterAllControllersIn("Sample.Mvc");
base.OnApplicationStarted();
}
/* ............. */
}
也许有人熟悉这个错误。
有什么建议吗?
最佳答案
你确定你真的在创建一个全新的Kernel
在您的 OnApplicationStarted
中从头开始每次调用它?如果您不是,并且您实际上创建了一次,但可能会运行两次注册位。请记住,您不能保证只有一个 App
在给定的 AppDomain 中实例化的类。
关于asp.net-mvc - 使用 Ninject.Web.Mvc 2.0 和 ASP.NET MVC 1.0 时出现错误 "More than one matching bindings are available",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2423862/