Ninject和ChildKernel在MVC3项目:"错误加载Ninject组件ICACHE" [英] Ninject and ChildKernel in MVC3 project: "Error loading Ninject component ICache"

查看:133
本文介绍了Ninject和ChildKernel在MVC3项目:"错误加载Ninject组件ICACHE"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的ASP.Net MVC3项目中使用Ninject(3.0)。在请求处理某些时候,我想执行一些任务。

I'm using Ninject (3.0) in my ASP.Net MVC3 project. At some point of request handling I want to execute some tasks.

我使用的session-per-request模式,但不希望这些任务可以共享同一个会话的当前请求了。所以,我以为,ChildKernels可以帮助我解决这个问题。我要创建子内核ISession的另一种约束力,但开始与:

I'm using session-per-request pattern but don't want these tasks to share the same Session as current Request has. So, I thought, ChildKernels could help me with this issue. I was going to create another binding for ISession in child kernel, but started with that:

var child = new Ninject.Extensions.ChildKernel.ChildKernel(NinjectMVC3.Kernel);
child.Dispose();

如果我请求期间执行code一样,我得到错误加载Ninject组件ICACHE 例外的在我的请求结束的(没有 .Dispose()调用)。如果我删除 child.Dispose()一切都很好。

If I execute the code like that during request I get Error loading Ninject component ICache exception at the end of my request (not at .Dispose() call). If I remove child.Dispose() everything is fine.

所以,我会选择正确的方式去与ChildKernel?它是安全使用孩子的内核没有明确的处置他们?为什么Ninject抛出在请求结束时,如果我处理掉孩子内核?

So, am I choosing the right way to go with ChildKernel? Is it safe to use the child kernels without explicitly disposing them? Why Ninject throws at the request end if I dispose the child kernel?

推荐答案

因为你所有的扩展模块加载到内核孩子的异常。创建具有LoadExtensions内核= FALSE会解决这个问题。但是,这不是你的情况的解决方案。

The exception is thrown because you load all the modules from the extensions into the child kernel. Creating the kernel with LoadExtensions=false would fix that problem. But this is not the solution in your case.

在ChildKernel的意图是不是真的不同的范围。您将需要对这个孩子内核的任务注册的一切。就在会议将是不够的。只需添加一个有条件的会话绑定是迄今为止更好的选择。

The intention of the ChildKernel isn't really for different scoping. You would need to register everything for the tasks on that child kernel. Just the session won't be enough. Adding just a conditional binding for the session is far the better option.

这篇关于Ninject和ChildKernel在MVC3项目:"错误加载Ninject组件ICACHE"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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