-
Notifications
You must be signed in to change notification settings - Fork 456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windsor adds a dependency resolved from typed factory as a burden on an unrelated object #436
Comments
➡ It seems to me that while it might be okay to dispose SqlConnections handed out via Since
@jonorossi @fir3pho3nixx Which way should we go? I'm hoping we can confirm the diagnosis and agree on a path forward as quickly as possible. (I appreciate your help!) I'll help implement if need be. |
It looks like the SqlConnection should not be added as a burden to either LongLivedService or ShortLivedViewModel. It's a total accident that the SqlConnection is being resolved during the call to ShortLivedViewModel's constructor. An async timing difference could have ended up resolving the SqlConnection at some later point; when that happens, it is not added as a burden. |
I'm pretty confident that this is the right change to make, so I went ahead: #439 |
Windsor 4.1.0 adds a dependency resolved from typed factory as a burden on an unrelated object. When that unrelated object is released, the dependency is disposed even though it's still in use by the object that actually resolved it.
This had been causing some hair-pulling all afternoon; sorry to bring another of these upon you. 😃
There's repro code at the end. Here's the clearest description I can write, besides the code itself:
➡ When a short-lived object depends on both a typed factory and a long-lived object which itself depends on the same typed factory, and the short-lived object’s constructor triggers the long-lived object to resolve a dependency of its own through the typed factory, Castle Windsor erroneously adds that dependency as a child burden to be disposed when the short-lived object is released. Even though that dependency was resolved by the long-lived service and the short-lived object does not know about it!
(In the real scenario, neither the long-lived or short-lived objects directly depend on the typed factory but rather they both depend on the same intermediate dependency which depends on the typed factory. I was able to remove the intermediate dependency and reproduce the same behavior.)
The debugger shows that the SqlConnection which the LongLivedService resolves is added as a burden to ShortLivedViewModel (breakpoint in
Burden.AddChild
).Self-contained repro:
Program.cs
CastleWindsorRepro.csproj
The text was updated successfully, but these errors were encountered: