[MAGNOLIA-6601] Model classes are not instantiated by Guice. Created: 15/Mar/16  Updated: 19/May/22  Resolved: 19/May/22

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

Type: Improvement Priority: Neutral
Reporter: Michiel Meeuwissen Assignee: Unassigned
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

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   

A component will be instantiated by guice, so they can also be scanned for interceptors. This however is not valid for model classes themselves.

I discovered this when I naively set a @CacheResult annotation on a method in a model class too (using https://github.com/vpro/jsr107-magnolia)

A component which we wire in a model class gets instantiated in com.google.inject.internal.ConstructorInjector#line 85

    try {
        Object[] parameters = SingleParameterInjector.getAll(errors, context, parameterInjectors);
        t = constructionProxy.newInstance(parameters);
        constructionContext.setProxyDelegates(t);
      } finally {

The model itself gets instantiated like this in info.magnolia.objectfactory.ObjectManufacturer#line line 118

 private Object newInstance(Constructor constructor, Object[] parameters) {
        try {
            return constructor.newInstance(parameters);
        } catch (InstantiationException e) {
            throw new MgnlInstantiationException(e);
        } catch (IllegalAccessException e) {
            throw new MgnlInstantiationException(e);
        } catch (InvocationTargetException e) {
            throw new MgnlInstantiationException(e);
        }
    }


 Comments   
Comment by Roman Kovařík [ 19/May/22 ]

Hello,

This ticket is now marked as closed due to one of the following reasons:

  • A long period of inactivity
  • Uses an old or Beta version of an application, module, or framework that we no longer support
  • The issue is no longer reproducible or has been fixed in later versions

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,
The Magnolia Team

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