That will work but is a bit dangerous; if you inject a global object,
its not too bad, but if you inject a session-scoped object into a
singleton service (not a threaded or pooled service), then a single
instance of the ASO will be shared across threads, which is not what
you want.
A more elaborate implementation could create a sub-class of the ASO
class as a proxy to the proper ASO.
On 1/17/06, Dmitry Gusev <[EMAIL PROTECTED]> wrote:
> Here is an example of creating ApplicationStateObjectProvider which allows
> you to inject ASOs via "aso" prefix, for instance:
>
> <service-point id="Resource"
> interface="org.apache.tapestry.engine.IEngineService">
> <invoke-factory>
> <construct class="ResourceService">
> <set-object property="sharedResourceProvider"
> value="aso:shared-resource-provider"/>
> </construct>
> </invoke-factory>
> </service-point>
>
> In order to do this we need to define an "aso" prefix for Application State
> Objects. We can do it like this in the hivemodule.xml:
>
> <contribution configuration-id="hivemind.ObjectProviders">
> <provider prefix="aso" service-id="ApplicationStateObjectProvider"/>
> </contribution>
>
> <service-point id="ApplicationStateObjectProvider"
> interface="org.apache.hivemind.service.ObjectProvider">
>
> An object provider based on Application State Objects
>
> <invoke-factory>
> <construct class="ApplicationStateObjectProvider">
> <set-object property="applicationStateManager"
> value="infrastructure:applicationStateManager"/>
> </construct>
> </invoke-factory>
>
> </service-point>
>
> Here we creating an object provider service that will manage ASOs via
> applicationStateManager. In fact we are injecting applicationStateManager
> into it. Here is an example of the ApplicationStateObjectProvider class:
>
> package org.keyintegrity.servicehub.csulengine.engine.state;
>
> import org.apache.hivemind.Location;
> import org.apache.hivemind.internal.Module;
> import org.apache.hivemind.service.ObjectProvider;
> import org.apache.tapestry.engine.state.ApplicationStateManager;
>
> public class ApplicationStateObjectProvider implements ObjectProvider {
>
> private ApplicationStateManager applicationStateManager;
>
>
> public Object provideObject(Module contributingModule, Class
> propertyType,
> String locator, Location location) {
>
> return applicationStateManager.get(locator);
> }
>
> public void setApplicationStateManager(ApplicationStateManager
> applicationStateManager) {
> this.applicationStateManager = applicationStateManager;
> }
> }
>
> Thats all. Hope this will help.
>
>
> 2006/1/16, Christian Haselbach <[EMAIL PROTECTED]>:
> >
> > Hello,
> >
> > injecting an ASO into a page or component is simple, but I cannot
> > figure out how to inject one into a service. Can anyone tell me
> > what to do?
> >
> > Thanke
> >
> > Regards, Christian
> >
> > P.S.: Injecting the ApplicationStateManager and obtaining the state
> > object from the it by name works fine, but this is not very direct.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
--
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind
Professional Tapestry training, mentoring, support
and project work. http://howardlewisship.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]