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

#1023 Updated implementation for ComponentPopulator #1028

Merged
merged 9 commits into from
Dec 20, 2023

Conversation

GuusLieben
Copy link
Member

@GuusLieben GuusLieben commented Nov 30, 2023

Type of Change

  • Enhancement (non-breaking change that affects existing code)

Description

The current primary implementation of ComponentPopulator, the ContextualComponentPopulator, is a remnant of the old core implementation with all the associated drawbacks. The class is chaotic, has too many responsibilities at once, and is not easily extended.

These changes introduce several strategies for a common StrategyComponentPopulator. This consists of two primary elements:

  • ComponentPopulationStrategy
  • ComponentInjectionPointsResolver

Population Strategies

Population strategies allow us to define what information should be injected into given injection points (e.g. fields or method parameters). The StrategyComponentPopulator is able to track a collection of strategies, so it remains possible to customize which strategies are applied. As component population is a core component of the ComponentFinalizingPostProcessor, it has been made configurable with appropriate customizers.

There are two built-in strategies:

  • ContextPopulationStrategy: This strategy is responsible for supporting injection points annotated with @Context, and resolving the appropriate context on the application context.
  • InjectPopulationStrategy: This strategy is responsible for supporting injection points annotated with @Inject, and obtaining the appropriate instance from the application context. The annotation(s) supported by this strategy are configurable, so support for custom injection markers is possible.

Both strategies have appropriate customization support, and can be (un)installed from the populator if preferred.

Injection Points Resolvers

To inject content into injection points, you first need to know what the injection points are. Injection points resolvers take care of this step. The default implementation is the MethodsAndFieldsInjectionPointResolver, which is also configurable in the configurer for StrategyComponentPopulator. This resolver respects the existing @Populate annotation, and will only include injection points compatible with this marker if it is present. If @Populate is not present, both methods and fields will be included as injection points.

Changes to context injection

Context types used to be injected into injection points decorated with @Context. This injection strategy has been rewritten to work with the @Inject annotation. If the target type is a child of Context, the strategy will first check if a compatible context is present in the application. If there is a compatible context, it will be used for injection. If no compatible context is present, regular injection will be used for fallback, if possible.

Checklist

  • I have performed a self-review of my own code
  • I have added tests that prove it is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Related issue number is linked in pull request title
  • I have added documentation that describes my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have rebased my branch on top of the latest develop branch

Related Issue

Closes #1023

@GuusLieben GuusLieben added this to the Release 0.6.0 milestone Nov 30, 2023
@GuusLieben GuusLieben self-assigned this Nov 30, 2023
@GuusLieben GuusLieben force-pushed the feature/#1023-component-populator branch from cf25b0c to 04de739 Compare November 30, 2023 18:39
@GuusLieben
Copy link
Member Author

Following up on CVE-2023-6378 in #1029 (0.5.1) and #1030 (0.6.0)

@GuusLieben GuusLieben force-pushed the feature/#1023-component-populator branch from 04de739 to fd8f10a Compare November 30, 2023 19:14
@GuusLieben
Copy link
Member Author

Pending: hooks for processing the value into the injection point

@GuusLieben GuusLieben force-pushed the feature/#1023-component-populator branch from 8231c6d to ddae45b Compare December 9, 2023 12:54
@GuusLieben GuusLieben force-pushed the feature/#1023-component-populator branch from 84c3a93 to c071a45 Compare December 20, 2023 15:05
@GuusLieben GuusLieben force-pushed the feature/#1023-component-populator branch from c071a45 to 3ca0deb Compare December 20, 2023 15:07
Copy link

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

6 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@GuusLieben GuusLieben merged commit f14206f into develop/0.6.0 Dec 20, 2023
6 of 7 checks passed
@GuusLieben GuusLieben deleted the feature/#1023-component-populator branch December 20, 2023 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Security: risk accepted Risk analyzed and accepted
Development

Successfully merging this pull request may close these issues.

Updated implementation for ComponentPopulator
1 participant