[MAGNOLIA-7507] Let GuiceParameterResolver support generics so that they could be used at least with ComponentProvider#newInstance Created: 10/Apr/19  Updated: 19/Dec/19  Resolved: 27/May/19

Status: Closed
Project: Magnolia
Component/s: None
Affects Version/s: None
Fix Version/s: 6.1

Type: Improvement Priority: Neutral
Reporter: Aleksandr Pchelintcev Assignee: Aleksandr Pchelintcev
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: 1h 34m
Time Spent: 56m
Original Estimate: Not Specified

Issue Links:
Relates
relates to MGNLUI-5187 Let UI components inject generics and... Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Sprint: Foundation 11

 Description   

Guice by design is pretty picky/complicated when it comes to generics. In order to let it inject generics, TypeLiteral workarounds have to be applied and we do not support that in our XML-based IoC configuration. Effectively, we only map the raw types regardless of the generic signature (whatever Class#forName produces while XML is read).

However, we can use the latter fact to our own benefit: when we create an instance of a type with ComponentProvider#newInstance(args) and some args are to be handled with Guice param resolver (i.e. - injected), we can detect that some of them are generic and then "downgrade" the Guice key resolution to raw type only (will work cause that's how we map them).

This allows e.g. UI framework to keep certain interfaces generic and yet injectable.

The only valid question in this situation - how do we eventually get the correctly parameterised instances? There could several soultions that come to my mind and probably cover the most of the potential use cases. Most common one - we need to inject some generic singleton/instance/definition, which is already cached in some UI bean store and is already of a "good" type. The parameter resolver will just locate it and will implicitly make a cast. Another use case - datasource bound components (depending on the datasource definition in context - different impls are used). This case will delegate type-correctness maintenance responsibility to UI configuration.


Generated at Mon Feb 12 04:24:23 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.