Ninject激活异常 [英] Ninject Activation Exception

查看:180
本文介绍了Ninject激活异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用asp.net的MVC 3,我使用ninject 2.2.1.0

I am using asp.net mvc 3. I am using ninject 2.2.1.0

 protected void Application_Start()
        {
            // Hook our DI stuff when application starts
            SetupDependencyInjection();
        }

        public void SetupDependencyInjection()
        {         
            // Tell ASP.NET MVC 3 to use our Ninject DI Container
            DependencyResolver.SetResolver(new NinjectDependencyResolver(CreateKernel()));
        }

        protected IKernel CreateKernel()
        {
            var modules = new INinjectModule[]
                              {
                                 new NhibernateModule(),
                                 new ServiceModule(),
                                 new RepoModule()
                              };

            return new StandardKernel(modules);
        }

以上是我如何设置,我从未有过的问题与任何它,直到我改变了我的jQuery UI选项卡阿贾克斯。

The above is how I setup and I never had a problem with any of it until I changed my jquery ui tabs to ajax.

现在我有页面加载,然后第一个标签被调用并执行一个Ajax请求。有些时候,我收到以下错误消息其他时间我不知道。我不知道为什么我收到了。

Now I have the page load then the first tab gets called and does an ajax request. Some times I get the following error message other times I don't. I am not sure why I am getting it.

Error activating _Page_Areas_Site_Views_Site_pDataTable_cshtml
More than one matching bindings are available.
Activation path:
  1) Request for _Page_Areas_Site_Views_Site_pDataTable_cshtml

Suggestions:
  1) Ensure that you have defined a binding for _Page_Areas_Site_Views_Site_pDataTable_cshtml only once.

我从来没有告诉ninject做绑定(我只是做我的回购和服务层),所以它必须做它自己。

I never told ninject to do binding(I only do my repos and service layers) so it must be doing it on it's own.

推荐答案

这可能不是作为一个实际的答案,但无论如何,我会去了。我遇到了同样的问题,使用MVC 2和Ninject 2.0。

This may not serve as an actual answer, but I'll go for it anyway. I ran into the same problem, using Mvc 2 and Ninject 2.0.

我工作的一个PhotoController简单地吐回图像的页面。它将被击中每个页面请求三十如此倍。我使用Ninject与我所有的控制器的依赖,并遇到了与特定的控制器的问题。

I was working on a PhotoController that simply spat back images to the page. It would be hit thirty or so times per page request. I was using Ninject for dependencies with all of my controllers, and ran into problems with that specific controller.

有时,Ninject会抛出您所遇到的完全相同的Activati​​onException。只有这样,才能使错误消失将重新启动应用程序池。

Sometimes, Ninject would throw the exact same ActivationException you are encountering. The only way to make the error go away would be to restart the app pool.

在小时摆弄周围试图确定原因的时间,的唯一结论我来是在哪里发生的一个非常大的数目相同的实例的请求。那是的只有的的PhotoController以及其他任何一个在项目中。区别

After hours and hours of fiddling around trying to determine the cause, the only conclusion I came to was that Ninject must have a problem injecting dependencies in cases where a very large number of requests for the same instance occur. That was the only difference between the PhotoController and any other one in the project.

我切换到使用通用的处理程序解决了这个问题,并在那之后不久,pre-确定Blob存储的URL。

I solved the problem by switching to using a generic handler, and shortly after that, pre-determined blob storage urls.

对不起,我不能更多的帮助,但<一href=\"http://stackoverflow.com/questions/4619167/one-controller-is-sometimes-bound-twice-with-ninject\">I张贴的问题一下我对堆栈的经验,从来没有一个解决它。

Sorry I can't be of more help, but I posted a question about my experience on stack and never got a resolution to it.

这篇关于Ninject激活异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆