2 Replies Latest reply on Apr 14, 2010 11:10 PM by Ryan Nideffer

    Proper way to pass Home objects

    Ryan Nideffer Newbie

      What is the accepted way to pass subclasses of EntityHome around? Currently I'm injecting/outjecting the entity itself:


      @In @Out private User user;



      In my Authenticator class, I am also injecting a UserHome object:


      @In private UserHome userHome;



      This seems ok in the auth class because I do user = userHome.find(user, pass), and the user is outjected to the Session context.


      However, I've got other actions that need access to the User object, which I inject.


      Should I be creating a new UserHome object in every action?


      Should this be done by injection with auto-creation? Or should I use Component.getInstance() to retrieve a new object.


      I think its a bit of a leaky abstraction that the the entity home objects can be constructed via the new operator and therefore not be Seam managed, causing all sorts of problems.


      How does everyone else handle this?


        • 1. Re: Proper way to pass Home objects
          Gabor Jakab Newbie

          I really do not understand your point here, but you do not create any EE components with new operator but retrieve reference to them in some way. The way you do this the best way depends on your business logic needs. Injection is really the easiest way but others are also not rocket science... If you want to keep some state in any components you can use contexts. You bind components to some context and retrieve them without explicit create like Component.getInstance(<yourComponent>, true). Conversation context is very useful in most cases...

          • 2. Re: Proper way to pass Home objects
            Ryan Nideffer Newbie

            Is there a way to enforce not using the new operator, is that something that everyone writing code needs to know not to do?