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

Fix Resolve Issue with Multiple AutoRegister Calls #155

Merged
merged 1 commit into from
Jan 27, 2022

Conversation

gillima
Copy link
Contributor

@gillima gillima commented Jan 24, 2022

The static list of ignore-types must not be changed to prevent side effects when resolving types with predicates.
Fixes #154

Comment on lines -3622 to +3625
if (registrationPredicate != null && !registrationPredicate(type))
{
ignoreChecks.Add(t => !registrationPredicate(t));
if (ignoreChecks.Any(c => c(type)))
return true;
}

for (int i = 0; i < ignoreChecks.Count; i++)
{
if (ignoreChecks[i](type))
return true;
}

return false;
return registrationPredicate != null && !registrationPredicate(type);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we know the context on why it was checking the registration Predicate first? Can you please request a review from the person who wrote this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the intention of @AlexanderMy was to early return if the predicate matches but then he forgot to remove the line that was adding the predicate to the (previous local) list.

Copy link

@OleksandrMyznikov OleksandrMyznikov Jan 26, 2022

Choose a reason for hiding this comment

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

@gillima is correct.

@@ -3582,7 +3582,7 @@ where localType.IsAssignableFrom(implementationType)
}

// TODO - find a better way to remove "system" assemblies from the auto registration
private readonly List<Func<Assembly, bool>> ignoredAssemlies = new List<Func<Assembly, bool>>()
private static readonly IReadOnlyList<Func<Assembly, bool>> ignoredAssemlies = new List<Func<Assembly, bool>>()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure how I feel about this being static. Would someone ever have more than one container instance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added IReadOnlyList to avoid modifications of the list but then realized my IDE suggests static ;-)
The assembly ignore list will not change if you have multiple containers. It could be written as (static) if's inside IsIgnoredAssembly but the list seems to be more elegant. Since the list is identically for all containers and will never change it can be made static to reduce memory consumption.

@niemyjski
Copy link
Collaborator

Thanks for the pr!

@niemyjski niemyjski merged commit 49889cc into grumpydev:master Jan 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TinyIoCResolutionException after multiple calls of AutoRegister
3 participants