6 Replies Latest reply on Oct 19, 2011 10:32 AM by Christian Sadilek

    problem with dependency injection of tree like dependency structure

    Gert Kropiunik Newbie



      I think I have found a problem when injecting dependencies into classes that themselfs get other objects injected which leads to a tree like structure. Here is the example I am working with:


      EntryPoint Class

          - EntryPoint depends on @ApplicationScoped ClassA

              - ClassA depends on @ApplicationScoped ClassB

          - EntryPoint depends on @ApplicationScoped ClassC

              - ClassC depends on @ApplicationScoped ClassD


      About 2 times out of 10 the application starts and works without problems. The other 8 times I get an exception during startup that one of the classes ClassA or ClassC cannot find one of the required dependencies.


      org.jboss.errai.ioc.rebind.ioc.InjectionFailure: unable to resolve type injector for: ClassB; at injection point: ClassA.(ClassB Display, org.jboss.errai.bus.client.framework.MessageBus MessageBus)    

        at org.jboss.errai.ioc.rebind.ioc.InjectionContext.getQualifiedInjector(InjectionContext.java:78)

                at org.jboss.errai.ioc.rebind.ioc.InjectUtil.resolveInjectionDependencies(InjectUtil.java:361)

                at org.jboss.errai.ioc.rebind.ioc.InjectUtil$1.generateConstructor(InjectUtil.java:95)

                at org.jboss.errai.ioc.rebind.ioc.TypeInjector.getType(TypeInjector.java:74)

                at org.jboss.errai.enterprise.rebind.JSR299IOCExtensionConfigurator$2.handle(JSR299IOCExtensionConfigurator.java:105)

                at org.jboss.errai.enterprise.rebind.JSR299IOCExtensionConfigurator$2.handle(JSR299IOCExtensionConfigurator.java:97)

                at org.jboss.errai.ioc.rebind.IOCProcessorFactory$1.process(IOCProcessorFactory.java:90)

                at org.jboss.errai.ioc.rebind.IOCProcessorFactory$ProcessingEntry.processAllDelegates(IOCProcessorFactory.java:215)

                at org.jboss.errai.ioc.rebind.IOCProcessorFactory.processAll(IOCProcessorFactory.java:172)

                at org.jboss.errai.ioc.rebind.ioc.bootstrapper.IOCBootstrapGenerator.generateExtensions(IOCBootstrapGenerator.java:159)

                at org.jboss.errai.ioc.rebind.ioc.bootstrapper.IOCBootstrapGenerator.generate(IOCBootstrapGenerator.java:145)

                at org.jboss.errai.ioc.rebind.IOCGenerator.generateIOCBootstrapClass(IOCGenerator.java:134)

                at org.jboss.errai.ioc.rebind.IOCGenerator.generate(IOCGenerator.java:102)

                at com.google.gwt.core.ext.GeneratorExtWrapper.generate(GeneratorExtWrapper.java:48)...


      After debugging the IOCBootstrapGenerator I found out that the MetaDataScanner contains the classes that have an @ApplicationScoped annotation in no special order. Also the MetaDataScanner.getTypesAnnotatedWith() method returns a Set of classes that is not ordered at all. The order is different every time I start the application. Some times it is correct and some times it is not. From that I saw the framework does not consider that ClassB and ClassD should be processed before ClassA and ClassC so that at the time when they will be processed (in IOCBootstrapGenerator.processAll()) the InjectionContext already contains the injectors for ClassB and ClassD.


      Is this something that should be improved in the framework or should I work around this issue e.g. by using my custom @Produces methods.