Wednesday, 20 January 2010

3 most commonly faced challenges to use Tapestry service (IOC)

  1. How to initialize one tapestry5 service at startup? Use Eager Load for this. eg: bind(MyServiceInterface.class, MyServiceImpl.class).eagerLoad();
2. How to use a tapestry5 service inside another T5 service which is eager loaded
Pass the service through the contructor, which will prevent from getting null pointer exceptions.
3. How to use multiple versions of a same service concurrently?
Can be done by using withId and withMarker attributes.
{ PARAMETER, FIELD }) @Retention(RUNTIME) @Documented public @interface Clustered {  }  @Target( { PARAMETER, FIELD }) @Retention(RUNTIME) @Documented public @interface InProcess {  }   public class MyModule {   public static void bind(ServiceBinder binder)   {     binder.bind(JobScheduler.class, ClusteredJobSchedulerImpl.class).withId("ClusteredJobScheduler").withMarker(Clustered.class);     binder.bind(JobScheduler.class, SimpleJobSchedulerImpl.class).withId("InProcessJobScheduler").withMarker(InProcess.class);   } }

No comments: