[MAGNOLIA-4471] Support for specifying multiple types on a component Created: 06/Jul/12 Updated: 19/May/22 Resolved: 19/May/22 |
|
| Status: | Closed |
| Project: | Magnolia |
| Component/s: | core |
| Affects Version/s: | 4.5.3 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Neutral |
| Reporter: | Tobias Mattsson | Assignee: | Unassigned |
| Resolution: | Won't Do | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||
| 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)
|
||||
| Date of First Response: | |||||
| Description |
|
When specifying a component in a module descriptor you give its type and its implementation (among other things). The key is the type you will be using when declaring a parameter to be injected in the constructor of another class. Such as: <component>
<type>info.magnolia.cms.i18n.MessagesManager</type>
<implementation>info.magnolia.cms.i18n.DefaultMessagesManager</implementation>
</component>
This works fine, except when there's a hierarchy of component providers. This test case illustrates the problem: public class GuiceMultipleKeysTest { public interface Interwoven { } @Singleton public static class Classified implements Interwoven { } public static void main(String[] args) { Injector parent = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(Interwoven.class).to(Classified.class); // Without this line child.getInstance(Classified.class) returns a new instance bind(Classified.class); } }); System.out.println(parent.getInstance(Interwoven.class)); System.out.println(parent.getInstance(Classified.class)); Injector child = Guice.createInjector(new GuiceParentBindingsModule(parent)); System.out.println(child.getInstance(Interwoven.class)); System.out.println(child.getInstance(Classified.class)); } } The problem is that the child injector only gets the explicit bindings from the parent and creates its own singleton when asked for Classified on the last line. Fixing this would mean adding support for multiple type declarations in module descriptors. It will also require restructuring the configuration objects used to represent the configuration and updating the code that actually adds them in Guice to support the multiple types. New format would be: <component>
<type>info.magnolia.cms.i18n.MessagesManager</type>
<type>info.magnolia.cms.i18n.AnotherInterface</type>
<implementation>info.magnolia.cms.i18n.DefaultMessagesManager</implementation>
</component>
|
| Comments |
| Comment by Roman Kovařík [ 19/May/22 ] |
|
Hello, This ticket is now marked as closed due to one of the following reasons:
If you are still facing a problem or consider this issue still relevant, please feel free to re-open the ticket and we will reach out to you. Thank you, |