与 OnePerRequestModule 相关的 Ninject 间歇性异常抛出

标签 ninject httpmodule ninject-2 ninject.web

我刚刚将 Ninject 的现有实现从 1.5 升级到 2.0。我现在看到在短时间内发生许多请求时会抛出间歇性异常。

这是正在抛出的异常。

Type: System.ArgumentException
Message: An item with the same key has already been added.
Source: Ninject
Stack Trace: at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at Ninject.Components.ComponentContainer.CreateNewInstance(Type component, Type implementation)
at Ninject.Components.ComponentContainer.ResolveInstance(Type component, Type implementation)
at Ninject.Components.ComponentContainer.Get(Type component)
at Ninject.Components.ComponentContainer.<CreateNewInstance>b__6(ParameterInfo parameter)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Ninject.Components.ComponentContainer.CreateNewInstance(Type component, Type implementation)
at Ninject.Components.ComponentContainer.ResolveInstance(Type component, Type implementation)
at Ninject.Components.ComponentContainer.Get(Type component)
at Ninject.Components.ComponentContainer.GetT
at Ninject.KernelBase.CreateContext(IRequest request, IBinding binding)
at Ninject.KernelBase.<>c__DisplayClassa.<Resolve>b__6(IBinding binding)
at System.Linq.Enumerable.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource x)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.<CastIterator>d__aa`1.MoveNext()
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
at Ninject.ResolutionExtensions.Get[T](IResolutionRoot root, IParameter[] parameters)
at NameOfConsumingSite.Application_BeginRequest(Object sender, EventArgs e)...



如果我删除 OnePerRequestModule,则不会抛出异常项目来自 httpModules在 web.config 中,但这会增加大量开销。

如果他们能提供帮助,我提前感谢任何人!

最佳答案

存在多线程问题。尝试使用在 https://github.com/ninject 中找到的 2.2 RC1 .请告诉我此版本是否仍然存在此问题,以确保我们在发布之前没有需要解决的其他问题。

关于与 OnePerRequestModule 相关的 Ninject 间歇性异常抛出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3841886/

相关文章:

c# - Ninject——如何使用 Parallel.ForEach 循环中使用的类进行 IOC

asp.net-mvc - 如何在 MVC 模块下禁用或重新调整 IIS DirectoryListingModule 的优先级?

c# - 友好的 URL 与丑陋的查询字符串 URL SharePoint、HTTPModule?

c# - 使用前端 Controller 和 IIS 提供静态文件的方法?

c# - ASP.NET MVC 3 : DefaultModelBinder with inheritance/polymorphism

unit-testing - 使用 Moq 模拟对象,在进行单元测试时使用 Ninject

.net - 我可以仅针对这种特定情况在 Ninject 中指定范围吗?

asp.net-mvc - 与 Ninject 的集成测试

c# - Ninject 与 WhenInjectedInto 扩展方法绑定(bind)

asp.net - 如何在 ASP.NET 中将 IHttpClientFactory 添加到 NInject