Skip to content
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

Fixed components resolved from typed factories being disposed along with unrelated objects #439

Merged

Conversation

jnm2
Copy link
Contributor

@jnm2 jnm2 commented Oct 6, 2018

Fixes #436.

@jonorossi I'm pretty confident that this is the right change to make. The fact that the factory is resolving in the call stack of the ShortLivedViewModel constructor call is accidental. Windsor should be acting the same as if the factory was resolving the component after a short delay (no longer in a component's constructor call stack). I added a comment to document this. Do you agree with this assessment?

A 4.1.1 release would be nice but in the meantime we'll gladly use the AppVeyor feed!

@@ -51,7 +51,7 @@ public interface IKernelInternal : IKernel

IDisposable OptimizeDependencyResolution();

object Resolve(Type service, IDictionary arguments, IReleasePolicy policy);
object Resolve(Type service, IDictionary arguments, IReleasePolicy policy, bool ignoreParentContext = false);
Copy link
Contributor Author

@jnm2 jnm2 Oct 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this parameter is a breaking change to implementors of IKernelInternal. Given the name IKernelInternal, I'm assuming users are expected to not be implementing this interface.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming users are expected to not be implementing this interface.

Correct, it is there because Castle used to have two containers, the MicroKernel and Windsor, the two got merged but obviously still visible from the code base.

return ResolveComponent(handler, service, additionalArguments, policy, ignoreParentContext: false);
}

private object ResolveComponent(IHandler handler, Type service, IDictionary additionalArguments, IReleasePolicy policy, bool ignoreParentContext)
Copy link
Contributor Author

@jnm2 jnm2 Oct 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original protected method above can be deleted if you don't think users will have inherited from DefaultKernel and called ResolveComponent(IHandler, Type, IDictionary, IReleasePolicy) from inside.

@jonorossi
Copy link
Member

Sorry for the delay, I'll check this out tomorrow.

@jnm2 jnm2 changed the title Typed factory burden on unrelated object Fixed components resolved from typed factories being disposed along with unrelated objects Oct 12, 2018
@jnm2 jnm2 force-pushed the typed_factory_burden_on_unrelated_object branch from a5b34ef to 73a7a7f Compare October 12, 2018 23:38
@jnm2
Copy link
Contributor Author

jnm2 commented Oct 12, 2018

Started a 'fixes' section in the changelog and removed whitespace trimming per @stakx's feedback on my other PR.

@jonorossi
Copy link
Member

I'm pretty confident that this is the right change to make. The fact that the factory is resolving in the call stack of the ShortLivedViewModel constructor call is accidental. Windsor should be acting the same as if the factory was resolving the component after a short delay (no longer in a component's constructor call stack). I added a comment to document this. Do you agree with this assessment?

Yes, this appears a like a sound change, I'm not familiar enough with the typed factory code to know if this could be done a little cleaner, but I'm happy for the change to go in. At least we've got a unit test for it now, and it knocks one typed factory defect off.

A 4.1.1 release would be nice but in the meantime we'll gladly use the AppVeyor feed!

I've created a 4.1 branch off v4.1.0, switch this pull request over to that base and we can get the change out. I'll get the change merged back into master.

@jonorossi jonorossi added this to the v4.1.1 milestone Oct 14, 2018
@jonorossi
Copy link
Member

[...] removed whitespace trimming per @stakx's feedback on my other PR.

I'm using trim_trailing_whitespace = true in my current project's editorconfig, if we added it with false would your editor behave?

@jnm2
Copy link
Contributor Author

jnm2 commented Oct 14, 2018

I'm using trim_trailing_whitespace = true in my current project's editorconfig, if we added it with false would your editor behave?

I know the editorconfig extension in VS Code would start behaving. I'd have to check on ReSharper/VS.

@jnm2 jnm2 changed the base branch from master to 4.1 October 14, 2018 15:33
@jnm2
Copy link
Contributor Author

jnm2 commented Oct 14, 2018

Thanks so much! 🎉 Switched branches.

Re: how clean of a change it is. I don't know either. My rationale is that the per-call-stack tracking is not appropriate (it's the cause of the problem) and that this is the simplest way to turn it off when it's not appropriate.

@jonorossi
Copy link
Member

Switched branches.

You'll need to rebase too, otherwise this pull request will drag 61 commits from master across.

@jnm2 jnm2 force-pushed the typed_factory_burden_on_unrelated_object branch from 73a7a7f to df7b635 Compare October 14, 2018 15:54
@jnm2
Copy link
Contributor Author

jnm2 commented Oct 14, 2018

@jonorossi Done, sorry! Did I update the changelog properly?

@jonorossi
Copy link
Member

Changelog looks good. Thanks.

@jonorossi jonorossi merged commit d463680 into castleproject:4.1 Oct 14, 2018
@jnm2 jnm2 deleted the typed_factory_burden_on_unrelated_object branch October 14, 2018 19:59
@robsonj
Copy link

robsonj commented Oct 31, 2018

I'm trying to upgrade from Castle.Windsor 4.1.0 to 4.1.1 and seeing a unit test failure between the two versions, the second assert fails in the following unit test for 4.1.1, is this expected behavior?

WindsorContainerTypedFactoryTests.cs.txt

@jonorossi
Copy link
Member

@robsonj could you please create a new issue referencing this pull request.

@robsonj
Copy link

robsonj commented Oct 31, 2018

Opened Issue #451, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants