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

Ignore required properties in the default autowiring property selector. #1369

Merged
merged 1 commit into from
Mar 6, 2023

Conversation

alistairjevans
Copy link
Member

Noticed during the docs creation for required properties, before this change any registrations with PropertiesAutowired applied would duplicate property injection with required properties.

I decided to just blanket ignore required properties in the DefaultPropertySelector. My logic for this was as follows:

  • Reflection-activated components will already have applied the mandatory property injection we've just added.
  • Lambda-activated components will have to create an instance of the object, so the compiler will force them to set those properties.
  • Instance components will have to have been created externally, so the compiler will have forced those properties to be set.

If someone inside a lambda uses Activator.CreateInstance directly (for some reason) to bypass the required properties, those required properties won't be injected; but then, why aren't you using the reflection activator?

@alistairjevans alistairjevans requested a review from tillig March 6, 2023 08:23
@codecov
Copy link

codecov bot commented Mar 6, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.04 🎉

Comparison is base (3489ad3) 78.49% compared to head (6f335e7) 78.53%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1369      +/-   ##
===========================================
+ Coverage    78.49%   78.53%   +0.04%     
===========================================
  Files          199      199              
  Lines         5715     5717       +2     
  Branches      1161     1162       +1     
===========================================
+ Hits          4486     4490       +4     
+ Misses         716      715       -1     
+ Partials       513      512       -1     
Impacted Files Coverage Δ
...Autofac/Core/Activators/DefaultPropertySelector.cs 81.25% <100.00%> (+2.67%) ⬆️
src/Autofac/Util/SequenceGenerator.cs 100.00% <0.00%> (+28.57%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@tillig tillig left a comment

Choose a reason for hiding this comment

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

The logic (re: use reflection vs lambda, etc.) is sound. I dig it. So let it be written, so shall it be done.

@tillig tillig merged commit 1910177 into develop Mar 6, 2023
@tillig tillig deleted the feature/ignore-required-props-in-prop-autowiring branch March 6, 2023 18:18
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.

2 participants