3 Replies Latest reply on Sep 10, 2008 3:39 PM by luxspes

    enforce new instance with create=true

    nimo22

      How can I enforce, that a new Instance of a class should be instantiated instead of searching a instance before creating a new?


      With


      @In(create=true)
      private Object o;



      I specifiy, that a component should be instantiated, only if the intance itself is null. (So it searches before it created a new one).


      Or should I do it with


      private Object o = new O();



      even it s a seam-managed Object.


      any suggestions?

        • 1. Re: enforce new instance with create=true
          blabno

          Never use constructor with seam components !!! You could use Component.forName(yourComponentName).newInstance() but consult with Pete if this is safe.

          • 2. Re: enforce new instance with create=true
            nimo22

            Why I am disallowed to use constructors ???
            (I can find this rule in the SEAM-Manual)


            Constructors in JAVA is one of the normal things.


            However, I had used constructors in Java before,
            without any (visible) problems.


            So I have to make a new instance with:


            Component.forName("test").newInstance();



            comes from the Component with


            @Name("test")



            • 3. Re: enforce new instance with create=true

              nimo mayr wrote on Sep 10, 2008 08:25:


              Why I am disallowed to use constructors ???
              (I can find this rule in the SEAM-Manual)


              Because with constructors, Seam IoC is not invoked and annotations like @In are ignored.