On Tue, 25 May 2010 07:07:05 -0300, Andreas Berg <si...@taz.de> wrote:

> The only way I see so far is to pass the service as parameters or by  
> constructor to my
> domains objects, which is not very nice.

It seems, I didn't fully understand constructor injection. In the
documentation, I see examples
to use constructor inejction to injection one service into another, but I
don't see any example
to inject a service into ordinary domain objects, which are not services (or
pages components either).

I'll outline my scenario a bit:

First my Page class, which a domain object "login" of class "User", which is
instatiated at some time
of the login process.

public class Index {

        @SessionState(create=false)
        @Property
        private User login;

        void onValidateForm () {
                
                if (loginForm.getHasErrors()) return;
                login = new User (userName,password);
                if (login == null) loginForm.recordError("Falsches Login");
        }
}

At some point, "User" makes use of other domain objects like "Group", for
which it may
need some directory service:

public interface DirectoryService {
  ...
}

which is in this case implemented by 

public class Ldap implements DirectoryService {
  ...
}

"DirectoryService"  is easily available in pages, components or services by
injection.
However If I want to utilize it in some domain objects of class "Group", I
would have
to pass it somehow starting from the creation of "login" in my page class
(see onValidateForm()
above) downwards somewhere, where instances of "Group" are created. It's
obviously
not nice to carry a lot of service objects through the business logic of my
application.
So I guess, there is a way to avoid that and leave it to Tapestry to inject
my service
at the level of domain objects just there, where I need it.

Is it ? If so, then I didn't find any code example, how to do it.

help would be appreceated.

andreas



-- 
View this message in context: 
http://old.nabble.com/Using---Injecting-Tapestry-5-services-in-objects-that-are-*not*-components---pages---services-tp28666562p28667564.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to