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

Inline dependencies aren't propagated by CollectionResolver #561

Closed
dvdwouwe opened this issue Nov 16, 2020 · 3 comments · Fixed by #562
Closed

Inline dependencies aren't propagated by CollectionResolver #561

dvdwouwe opened this issue Nov 16, 2020 · 3 comments · Fixed by #562

Comments

@dvdwouwe
Copy link
Contributor

If you change the behavior of the DefaultKernel to propagate inline dependencies, all sub-resolvers should pass the AdditionalArguments from their CreationContext.

...
var container = 
new WindsorContainer(
	new DefaultKernel(
		new InlineDependenciesPropagatingDependencyResolver(),
		new DefaultProxyFactory()),
	new DefaultComponentInstaller());
...
public class InlineDependenciesPropagatingDependencyResolver
			: DefaultDependencyResolver
{
	protected override CreationContext RebuildContextForParameter(
		CreationContext current,
		Type parameterType)
	{
		return parameterType.GetTypeInfo().ContainsGenericParameters
			? current
			: new CreationContext(parameterType, current, true);
	}
}

I will create a PR for this, with a unit-test that confirms the behavior.

PS
This will affect implicitly the code for .Net Core 3.1 / 5.0, because there is a class called RegisteredCollectionResolver. The registering of this class can't be easily undone with the current code-base.

@generik0
Copy link
Contributor

@dvdwouwe I see the value in this. Is there any way this could break existing implementations? Do you think there a reason why the original implementation did not pass this?

@dvdwouwe
Copy link
Contributor Author

I fixed the original implementation in the class CollectionResolver, by passing the context.AdditionalParameters:

		public virtual object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model,
		                              DependencyModel dependency)
		{
			return kernel.ResolveAll(GetItemType(dependency.TargetItemType), ** context.AdditionalArguments **);
		}

I don't think this change it has any impact , because:

  • if propagating from the parent is disabled (default), then context.AdditionalArguments is null
  • if propagating from the parent is enabled (you can see this in the unit-test code), then context.AdditionalArguments is propagated and not null

So, in the default mode context.AdditionalArguments is null, so there is no difference. Only if we use the possibility to pass parent context we need this fix.
At the moment I have to recreate a correct CollectionResolver, and it goes further, because in core 3.1 there is automatically a register of RegisteredCollectionResolver. So it is best to just fix the base class CollectionResolver.

@jonorossi
Copy link
Member

Thanks @dvdwouwe, apologies for the slow response. Merged.

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 a pull request may close this issue.

3 participants