1 Reply Latest reply on Nov 18, 2011 12:33 PM by Dominik Obermaier

    Injection in not container managed class

    Dominik Obermaier Newbie

      Hi,

       

      I am using the GXT MVC Framework for developing my application. My Problem is, that the Views have to get created manuall, since there is no default Constructor (and the parameters can not get injected, because I have to pass the current Controller Instance like "new MyView(this)").

       

      In this view I want to use dependency injection. The view is not container managed so of course I can not  use @Inject. In Seam2 there is a class called "Component" and one can do "Component.getInstance(MyClass.class" to create a new container managed instance where the dependencies get injected.

       

      For CDI there is a utility class which does exactly that called BeanInject (https://github.com/softwaremill/softwaremill-common/tree/master/softwaremill-cdi). But I can not use this class in Client Code, because it uses Reflection classes.

       

      Since Errai can do Dependency Injection in Client Code, I hope there is a Errai utility class which I can use in my code for "on demand" dependency Injection. Can you point me to the right direction? Thanks!

        • 1. Re: Injection in not container managed class
          Dominik Obermaier Newbie

          I finally got it working. Essentially I did inject everything by Field Injection (In my usecase I had cyclomatic injections, which are not supported in Errai). So everything could get wired up at startup time.

           

          The problem with ExtGWT MVC Framework was easy: In my View Class I just called the super constructor with null and Injected the Controller. I created a @PostCreation method wich set the super Controller instance to the injected controller. (This was possible, since the Controller had protected scope.).

           

          So essentially the problem is the ExtGWT MVC Frameworks architecture. What I did is just a workaround, but no solution for a complex application, since the ability to lazy load views is lost.

           

          Thanks @csadilek for helping me with my issue on IRC.