I confess I don't follow the problem you're trying to solve here, but
to directly answer "how do I post-process an object constructed by
Guice", try com.google.inject.spi.InjectionListener

-d

On Dec 13, 8:30 am, Mario Scalas <[email protected]> wrote:
> Hi all,
>   in my eclipse-based application i've modelled model-view-presenter
> as different classes leaving the wiring (View to Presenter and
> Presenter-to-Model, and data-binding between model and view) to guice.
> Now I've used Peaberry Eclipse extension in order to let guice create
> and inject the View object and then pass it to the Eclipse framework.
>
> Though, I also need that after Eclipse class the createPartControl()
> method on the view, databinding code is run to wire the view to the
> model (using Eclipse Databinding API). That is, I need post-processing
> the object when such method is called.
> I've resorted to write an interceptor to do this:
>
> // In my module:
> public class LoginMVPConfig extends AbstractModule {
>         @Override protected void configure() {
>                 bindModel( ILoginPresentationModel.class )
>                         .toView( ILoginView.class )
>                         .build();
>         }
>
>         protected <T> DataBinder<T> bindModel( Class<T> modelType ) {
>                 return new DataBinder<T>( binder(), modelType );
>         }
>
> }
>
> // Databinding DSL and glue-code
> public class DataBinder<T> {
>         private final Class<T> modelType;
>         private final Binder binder;
>         private List<Class<?>> viewTypes;
>
>         public DataBinder( Binder binder, Class<T> modelType ) {
>                 this.binder = binder;
>                 this.modelType = modelType;
>                 this.viewTypes = new ArrayList<Class<?>>();
>         }
>
>         public DataBinder<T> toView( Class<?> viewType ) {
>                 viewTypes.add( viewType );
>                 return this;
>         }
>
>         /**
>          * For each pair (model, view[i]) a method interceptor is created in
> order to perform databinding when
>          * a method annotated with {...@link PostConstruct} annotation is
> executed.
>          */
>         public void build() {
>                 for (Class<?> viewType : viewTypes) {
>                         DataBindingPostProcessor dataBinder = new 
> DataBindingPostProcessor(
>                                         binder.getProvider( modelType ) );
>                         binder.bindInterceptor( only( viewType ), 
> annotatedWith
> ( PostConstruct.class ), dataBinder );
>                         binder.requestInjection( dataBinder );
>                 }
>         }
>
> public class DataBindingPostProcessor implements MethodInterceptor {
>         private final Provider<?> modelProvider;
>
>         @Inject
>         private IDataBindingService dataBindingService;
>
>         public DataBindingPostProcessor( Provider<?> modelProvider ) {
>                 super();
>                 this.modelProvider = modelProvider;
>         }
>         @Override public Object invoke( MethodInvocation methodInvocation )
> throws Throwable {
>                 Object result = methodInvocation.proceed();
>                 Object theView = methodInvocation.getThis();
>                 dataBindingService.bind( theView, modelProvider.get() );
>                 return result;
>         }
>
> }
>
> That is I'm creating an interceptor for each (view,model) pair: which
> means that I'm going to have a lot of interceptors in my application!
> Is there any alternative approach for solving my problem?
>
> Hope I've been clear enough,
> Mario

--

You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.


Reply via email to