I faced the same problem.
I found the following solution to register the PersistFilter several times.

you can inject the session provider as follows.

    @Inject @MyDataSourceOne
    private Provider<Session> sessionProvider;


---

@Retention(RetentionPolicy.RUNTIME)
@Target({ FIELD, PARAMETER, METHOD })
@BindingAnnotation
public @interface MyDataSourceOne {}


@Retention(RetentionPolicy.RUNTIME)
@Target({ FIELD, PARAMETER, METHOD })
@BindingAnnotation
public @interface MyDataSourceTwo {}


public class MyDataSourceOnePersistModule extends PrivateModule {
    public static final Key<PersistFilter> MY_DATA_SOURCE_ONE_FILTER_KEY = 
Key.get(PersistFilter.class, MyDataSourceOne.class);

    public void configure() {
        final JpaPersistModule jpm = new 
JpaPersistModule("myDataSourceOne");
        jpm.properties(new Properties()); // some kinda bug without this
        
        install(jpm);

        
bind(Session.class).annotatedWith(MyDataSourceOne.class).toProvider(MyDataSourceOneSessionProvider.class);
        expose(Session.class).annotatedWith(MyDataSourceOne.class);
        
        bind(MY_DATA_SOURCE_ONE_FILTER_KEY).to(PersistFilter.class);
        expose(MY_DATA_SOURCE_ONE_FILTER_KEY);
    }
}


public class MyDataSourceTwoPersistModule extends PrivateModule {
    public static final Key<PersistFilter> MY_DATA_SOURCE_TWO_FILTER_KEY = 
Key.get(PersistFilter.class, MyDataSourceTwo.class);

    public void configure() {
        final JpaPersistModule jpm = new 
JpaPersistModule("myDataSourceTwo");
        jpm.properties(new Properties()); // some kinda bug without this
        
        install(jpm);

        
bind(Session.class).annotatedWith(MyDataSourceTwo.class).toProvider(MyDataSourceTwoSessionProvider.class);
        expose(Session.class).annotatedWith(MyDataSourceTwo.class);
        
        bind(MY_DATA_SOURCE_TWO_FILTER_KEY).to(PersistFilter.class);
        expose(MY_DATA_SOURCE_TWO_FILTER_KEY);
    }
}


public class WebModule extends ServletModule {

    protected void configureServlets() {
        install(new MyDataSourceOnePersistModule());
        install(new MyDataSourceTwoPersistModule());
        
        // more bindings
        
        
filter("/*").through(MyDataSourceOnePersistModule.MY_DATA_SOURCE_ONE_FILTER_KEY);
        
filter("/*").through(MyDataSourceTwoPersistModule.MY_DATA_SOURCE_TWO_FILTER_KEY);
    }
    
}

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-guice/-/vaqrI74Sh7EJ.
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