On 08/18/2012 05:36 PM, George Christman wrote:
I have a few questions about the tapestry services. I'd like to be able to
Inject services in these classes, however I'm a little confused. I
understand if you want to be able to Inject a service, you must first bind
the service in the app module. However, I'm not sure if I would need to
first bind the class I'm trying to Inject the service into.

I'm also uncertain how I would go about binding an abstract class like
below, or is it inherited from the base class.

Lastly is there away to setup an entire package to work with services like
tapestry pages and components work without having to bind every class within
the task. Perhaps my understanding isn't completely clear.

A few classes and some sample code below to hopefully help clarify what I'm
trying to do.

Thanks.

public class DMSImport {

         Parser parser = DMSFactory.getParser(value1, value2, value3);

}

  public abstract class Parser {

         @Inject
         private VehicleDAO vehicleDAO;

         public Parser(String value1, String value2, String value3) {
         //Sets attributes
         vehicleDAO.setVehicle(value1);
         }

          protected abstract void parse(Reader dataReader, ParserCallback
callback) throws IOException;

}

public class AutoMateParser extends Parser {
     public AutoMateParser (String  value1, String value2, String value3) {
         super(value1, value3, value3);
     }

     protected void parse(Reader dataReader, ParserCallback callback) throws
IOException {
     //some code
     }
}

public class DMSFactory {

     public static Parser getParser(String value1, String value2, String
value3) {
         switch (dms) {
             case DatabaseConstants.INTEGRATION_IMPORTSYSTEM_AUTOMATE:
                 return new AutoMateParser(value1, value2, value3);
             case
             //many other parsers that are setup identical to the
AutoMateParser
          }
     }
}




You only need to bind services. You can inject those services into other classes with the @Inject or @InjectService annotation.

I'm still working my way through how it all works. You don't bind abstract classes. You bind a class to the interface which it fully implements. You can use abstract classes between the interface and the class that is being bound with it, but in the end you can't bind abstract classes.

Which pieces are you trying to turn into a service? It looks like the VehicleDAO is a service, but from what little I can tell, it shouldn't be. Services need to be thread safe, so typically all of the class variables are declared final.

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

Reply via email to