即使每个Web请求都明确声明,Castle Windsor实例也会注册为单例 [英] Castle windsor instances are registered as singleton even though explicitly declare per web request
本文介绍了即使每个Web请求都明确声明,Castle Windsor实例也会注册为单例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在根据Web请求生命周期明确声明我的注册,但是它们仍然是单例。
I am explicitly declaring my registerations as per web request lifecycle but they are still singletons.
这是一个问题,因为我的命令处理程序依赖于IDbConnection,该IDbConnection也是
this is a problem because my command handlers depend on an IDbConnection which is also registered per web request.
这是我的注册代码:
container.Register(
Classes
.FromAssemblyContaining<EcruiterCommands>()
.BasedOn(typeof (ICommandHandler<>))
.WithService.AllInterfaces()
.LifestylePerWebRequest());
推荐答案
我发现了问题,罪魁祸首是这一行:
I found the issue, the culprit is this line:
.BasedOn(typeof (ICommandHandler<>))
它会重置注册。
这篇关于即使每个Web请求都明确声明,Castle Windsor实例也会注册为单例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文