-
Notifications
You must be signed in to change notification settings - Fork 235
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
Conversation
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>>() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Thanks for the pr! |
The static list of ignore-types must not be changed to prevent side effects when resolving types with predicates.
Fixes #154