[
http://jira.magnolia-cms.com/browse/MAGNOLIA-4471?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Tobias Mattsson updated MAGNOLIA-4471:
--------------------------------------
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:
{code}
<component>
<type>info.magnolia.cms.i18n.MessagesManager</type>
<implementation>info.magnolia.cms.i18n.DefaultMessagesManager</implementation>
</component>
{code}
This works fine, except when there's a hierarchy of component providers. This
test case illustrates the problem:
{code}
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));
}
}
{code}
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:
{code}
<component>
<type>info.magnolia.cms.i18n.MessagesManager</type>
<type>info.magnolia.cms.i18n.AnotherInterface</type>
<implementation>info.magnolia.cms.i18n.DefaultMessagesManager</implementation>
</component>
{code}
was:
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:
{code}
<component>
<type>info.magnolia.cms.i18n.MessagesManager</type>
<implementation>info.magnolia.cms.i18n.DefaultMessagesManager</implementation>
</component>
{code}
This works fine, except when there's a hierarchy of component providers. This
test case illustrates the problem:
{code}
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));
}
}
{code}
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:
{code}
<component>
<type>info.magnolia.cms.i18n.MessagesManager</type>
<type>info.magnolia.cms.i18n.AnotherInterface</type>
<implementation>info.magnolia.cms.i18n.DefaultMessagesManager</implementation>
</component>
{code}
> Support for specifying multiple types on a component
> ----------------------------------------------------
>
> Key: MAGNOLIA-4471
> URL: http://jira.magnolia-cms.com/browse/MAGNOLIA-4471
> Project: Magnolia
> Issue Type: Improvement
> Security Level: Public
> Components: core
> Affects Versions: 4.5.3
> Reporter: Tobias Mattsson
> Assignee: Philipp Bärfuss
>
> 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:
> {code}
> <component>
> <type>info.magnolia.cms.i18n.MessagesManager</type>
>
> <implementation>info.magnolia.cms.i18n.DefaultMessagesManager</implementation>
> </component>
> {code}
> This works fine, except when there's a hierarchy of component providers. This
> test case illustrates the problem:
> {code}
> 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));
> }
> }
> {code}
> 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:
> {code}
> <component>
> <type>info.magnolia.cms.i18n.MessagesManager</type>
> <type>info.magnolia.cms.i18n.AnotherInterface</type>
>
> <implementation>info.magnolia.cms.i18n.DefaultMessagesManager</implementation>
> </component>
> {code}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.magnolia-cms.com/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
----------------------------------------------------------------
For list details, see: http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------