Re: T5 service injection outside pages
You could still write a constructor with your service dependencies as parameters, Tapestry will fill those in upon instantiation. Howard mentioned the ObjectLocator some while ago which provides a getService() method. If you inject this in your page and pass it along to your business logic you should be able to access your services. Uli Am Do, 3.07.2008, 10:44, schrieb Udo Abel: OK, but then I'll end up with all classes being services, since basic services like logging, configuration, etc. will be used in almost any class. I've found no way to circumvent that, since I've noticed that the @InjectService annotation can only be used as a parameter declaration to a method. So I can't call that mehod myself anymore from a normal class. That would mean that the world of services is isolated against normal POJOs... Frankly, I think I'll take the normal approach with singletons for the services used in my business logic. Thanks anyway. Udo. Original-Nachricht Datum: Thu, 3 Jul 2008 09:53:38 +0200 (CEST) Von: Ulrich Stärk [EMAIL PROTECTED] An: Tapestry users users@tapestry.apache.org Betreff: Re: T5 service injection outside pages You'll have to declare those classes where you want to use your service as services too, i.e. you either have to write a buildXXX method in your AppModule or do a binder.bind(). You can then either use the @InjectService annotation to inject your service or just write a constructor with the desired service as a paramater and Tapestry will do the rest for you. Uli Am Do, 3.07.2008, 09:40, schrieb Udo Abel: Hi, in my app, I have a service which works OK in pages and component classes, but of course a lot of business logic is outside of those classes in separate packages, where I need that service, too. But if I simple @Inject it as in page classes, it does not work (i.e. is null). Is the injection limited to pages (maybe because they get transformed on startup)? Or do I need to do something else for injection outside of pages? Thanks, Udo. -- Pt! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger - 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] -- GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen! Jetzt dabei sein: http://www.shortview.de/[EMAIL PROTECTED] - 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]
Re: T5 service injection outside pages
all services defined by the Tapestry IOC container are per default singletons (as in Spring). if you want to access services from outside you have to obtain the service from the IOC registry directly. then you can call the method of a well defined and initialized service. Tapestry uses constructor injection, Spring uses setter injection and constructor injection. guice does as well. therefore all you have to do to get the logging service is to declare it in the constructor (within the container). EJB 3 offers ways to inject services into any pojo by only declaring it as such (@EJB,...) without setter or constructor declaration ... but you have to remember that every class runs in the EJB container, therefore its not a simple pojo anymore because it has already been altered at the bytecode level by the EJB container as any IOC container does to. in short: dependency injection is only available in container managed classes. the downside of the EJB 3 approach: how do yout test your classes if you have no way of setting the references; except you start the container? in my case business logic classes are simple services that are also configured using the IOC container. g kris Udo Abel [EMAIL PROTECTED] 03.07.2008 10:44 Bitte antworten an Tapestry users users@tapestry.apache.org An Tapestry users users@tapestry.apache.org Kopie Thema Re: T5 service injection outside pages OK, but then I'll end up with all classes being services, since basic services like logging, configuration, etc. will be used in almost any class. I've found no way to circumvent that, since I've noticed that the @InjectService annotation can only be used as a parameter declaration to a method. So I can't call that mehod myself anymore from a normal class. That would mean that the world of services is isolated against normal POJOs... Frankly, I think I'll take the normal approach with singletons for the services used in my business logic. Thanks anyway. Udo. Original-Nachricht Datum: Thu, 3 Jul 2008 09:53:38 +0200 (CEST) Von: Ulrich Stärk [EMAIL PROTECTED] An: Tapestry users users@tapestry.apache.org Betreff: Re: T5 service injection outside pages You'll have to declare those classes where you want to use your service as services too, i.e. you either have to write a buildXXX method in your AppModule or do a binder.bind(). You can then either use the @InjectService annotation to inject your service or just write a constructor with the desired service as a paramater and Tapestry will do the rest for you. Uli Am Do, 3.07.2008, 09:40, schrieb Udo Abel: Hi, in my app, I have a service which works OK in pages and component classes, but of course a lot of business logic is outside of those classes in separate packages, where I need that service, too. But if I simple @Inject it as in page classes, it does not work (i.e. is null). Is the injection limited to pages (maybe because they get transformed on startup)? Or do I need to do something else for injection outside of pages? Thanks, Udo. -- Pt! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger - 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] -- GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen! Jetzt dabei sein: http://www.shortview.de/[EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]