If I am on the right track now, this should work:

1. An own ThreadLocale implementation that returns the Locale depending on the 
domain.

2. The RequestGlobals is injected inside of this ThreadLocale implementation

3. The new ThreadLocale implementation is linked to the DomainDepThreadLocale 
in the AppModule.

?

The method getLocale() is never called though :-(



public class DomainDepThreadLocale implements ThreadLocale {

        private final RequestGlobals requestGlobals;

        public DomainDepThreadLocale(final RequestGlobals requestGlobals) {
            super();
            this.requestGlobals = requestGlobals;
    }

        
        public Locale getLocale() {

                if 
(this.requestGlobals.getHTTPServletRequest().getServerName().equals("www.domain.de")){
                        return Locale.GERMAN;
                }
                
                return Locale.ENGLISH;
    }

        public void setLocale(Locale locale) {
    }

        
        
}

and then:

public class AppModule
{
        
         @Inject
         private ThreadLocale threadLocale;

    public static void bind(ServiceBinder binder)
    {
        
        binder.bind(ThreadLocale.class,DomainDepThreadLocale.class);
    }


Or am I still getting it wrong?

Thanks!

Toby

-------- Original-Nachricht --------
> Datum: Sat, 22 Nov 2008 08:52:00 -0800
> Von: "Howard Lewis Ship" <[EMAIL PROTECTED]>
> An: "Tapestry users" <users@tapestry.apache.org>
> Betreff: Re: @InjectService("RequestGlobals")

> On Sat, Nov 22, 2008 at 6:40 AM,  <[EMAIL PROTECTED]> wrote:
> > Ok, let me summarize how I understood the IOC documentation:
> >
> > 1. Inside AppModule, every public method that exists is called when the
> webapplication is loaded for the first time.
> >
> > 2. every method that starts with build..... will generate an IOC service
> with the name followed by the keyword "build."
> >
> > Example:
> >
> >  "public buildMyService ()" will lead to a new IOC service called
> MyService.
> >
> >
> > 3. if such a method contains variables, services with the variables'
> names are searched inside the IOC registry...and are automatically injected
> into the service. The @Inject is not necessary sometimes (if it is a "shadow
> service").
> >
> > Example 1:
> 
> We're talking about parameters here, parameters to the method, not
> simple variables.
> 
> Please check into the documentation; generally you just need a service
> interface and an implementation, with dependencies provided via the
> implementation's constructor parameters.  Service builder method fill
> a specialized niche.
> 
> >
> > public buildMyService (final Logger log) // injects the IOC Service with
> the name "Logged" automatically which is a shadow service, otherwise it
> would be:
> 
> Logger is special; it is a resource available to the service, rather
> than a dependency (another service).  Again, check the documentation.
> 
> >
> > public buildMyService (@InjectService final Logger log)
> >
> > Example 2:
> >
> > public buildMyService (final Logger log, final RequestGlobals
> requestGlobals)
> >
> > would inject the shadow service RequestGlobals.
> 
> Yes, because there is exactly ONE service which implements this
> interface. No ambiguity, so no problem.  The implementation of the
> service doesn't matter (i.e. that it is a shadow service ... in fact,
> it is not, Request is a property shadow of RequestGobals.request;
> RequestGlobals is a service with scope "perthread" ... none of this is
> relevant to injection!).
> 
> >
> > Example 3:
> >
> > public buildMyService (final Logger log, final RequestGlobals
> requestGlobals, @InjectService ThreadLocale threadLocale)
> 
> This would fail; you use @InjectService("ServiceId") when injecting
> just by type doesn't work (because more than one service implements
> the interface). In this example, omit the @InjectService annotation
> and it will work.
> 
> >
> > would inject the shadow service RequestGlobals and the normal IOC
> service threadLocale
> 
> Again, services are services; scope and implementation are details
> about the implementation of the service that are not relevant to the
> user of the service.
> 
> >
> > Is this how it works?
> >
> > Thanks!
> >
> > Toby
> >
> > -------- Original-Nachricht --------
> >> Datum: Fri, 21 Nov 2008 08:51:52 -0800
> >> Von: "Howard Lewis Ship" <[EMAIL PROTECTED]>
> >> An: "Tapestry users" <users@tapestry.apache.org>
> >> Betreff: Re: @InjectService("RequestGlobals")
> >
> >> Do you see what your doing for the Logger?  Do the same thing.
> >>
> >> On Fri, Nov 21, 2008 at 5:57 AM,  <[EMAIL PROTECTED]> wrote:
> >> > How do you inject RequestGlobals inside of AppModule ?
> >> >
> >> > I have tried:
> >> >
> >> >  public RequestFilter buildTimingFilter(final Logger log)
> >> >    {
> >> >        return new RequestFilter()
> >> >        {
> >> >
> >> >
> >> >            public boolean service(Request request, Response response,
> >> >                        RequestHandler handler)
> >> >                    throws IOException
> >> >            {
> >> >
> >> >
> >> >                @InjectService("RequestGlobals") RequestGlobals
> >> requestGlobals;
> >> > // disallowed for this location
> >> >
> >> >
> >> > Inside of:
> >> >
> >> >  public boolean service(Request request, Response response,
> >> >                        @InjectService("RequestGlobals")
> RequestGlobals
> >> requestGlobals,
> >> >                        RequestHandler handler)
> >> >                    throws IOException
> >> >
> >> > it does not work because the service method needs to have 2
> parameters
> >> only.....
> >> >
> >> >
> >> > Inside of here:
> >> >
> >> >  public RequestFilter buildTimingFilter(final Logger log)
> >> >    {
> >> >        return new RequestFilter()
> >> >        {
> >> >
> >> >                @InjectService("RequestGlobals") RequestGlobals
> >> requestGlobals,
> >> >
> >> > it is also disallowed.
> >> >
> >> >
> >> > The same here:
> >> >
> >> >  public RequestFilter buildTimingFilter(final Logger log)
> >> >    {
> >> >
> >> >        @InjectService("RequestGlobals") RequestGlobals
> requestGlobals,
> >> >
> >> >
> >> > or here:
> >> >
> >> >
> >> >        @InjectService("RequestGlobals") RequestGlobals
> requestGlobals,
> >> >
> >> >    public RequestFilter buildTimingFilter(final Logger log)
> >> >    {
> >> >
> >> >
> >> > I can not find any other places to put this @InjectService
> annotation.
> >> >
> >> > Any help is appreciated....
> >> >
> >> > Thanks!
> >> >
> >> > Toby
> >> >
> >> >
> >> >
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> > For additional commands, e-mail: [EMAIL PROTECTED]
> >> >
> >> >
> >>
> >>
> >>
> >> --
> >> Howard M. Lewis Ship
> >>
> >> Creator Apache Tapestry and Apache HiveMind
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> For additional commands, e-mail: [EMAIL PROTECTED]
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> 
> 
> 
> -- 
> Howard M. Lewis Ship
> 
> Creator Apache Tapestry and Apache HiveMind
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to