我使用的是MVC 3,根據不同的存儲庫我有一系列控制器,我的存儲庫中有一個依賴於http上下文會話。 爲了使用Windsor-Castle IoC,我爲每個存儲庫創建了接口。Windsor Castle IoC - Http Session
如何將當前會話對象傳遞給需要它的存儲庫?
我曾經是能夠做到這一點和「解決」會照顧會話傳遞給需要它的存儲庫中,不知何故,我不能在最新版本中做到這一點(2.5.3 2011年2月):
Protected Overrides Function GetControllerInstance(ByVal requestContext As System.Web.Routing.RequestContext, _
ByVal controllerType As System.Type) As System.Web.Mvc.IController
Dim match As IController
' 1 or more components may need the session,
' adding it as a (possible) dependency
Dim deps As New Hashtable
deps.Add("session", HttpContext.Current.Session)
match = container.Resolve(controllerType, deps)
Return match
End Function
謝謝,文森特