If I understood your question correctly, the answer is no. There is no way to do this.

But to make sure I didn't miss read your question:
- AbstractRepo requires MTUnitOfWork
- MTUnitOfWork requires MTPersistServiceImpl
- MTPersistServiceImpl requires @Named(PersistConsts.JPA_UNIT_NAME)

What you want is:
- guice should inject a different MTUnitOfWork with a different MTPersistServiceImpl depending on the concrete class of AbstractRepo.

guice does not offer this kind of decision making.

What you could do:
Use AssistedInjection to pass the JpaUnitName from the AbstractRepo instance to the MTUnitOfWork and from there to the MTPersistService.




On 09/19/2013 04:32 PM, Alex Khomchenko wrote:
Hello everyone.

Sorry for my bad English.

I have a problem with injection condition. There is custom made MultitenancyPersistence and I want to use different persistence units for different repository.

Here is my code:

I've got:

public class MultiTenantPersistServiceImpl  implements PersistService {

...

@Inject
public MultiTenantPersistServiceImpl(@Named(PersistConsts.JPA_UNIT_NAME) String jpaUnitName) { ... }

...

}

and:

public class MultiTenantUnitOfWorkImpl implements UnitOfWork, EntityManagerProvider {

...

@Inject
public MultiTenantUnitOfWorkImpl(MultiTenantPersistServiceImpl persistService) {}

...

}

which is used throw Provider at repo:

public abstract class AbstractRepo {
...

   @Inject
   private EntityManagerProvider entityManagerProvider;


   protected EntityManager getEntityManager() {
       return entityManagerProvider.get();
   }

...
}

and extended by:

public abstract class AbstractFirstDbRepo extends AbstractRepo { ... }
 public abstract class AbstractSecondDbRepo extends AbstractRepo { ... }

and binded at module:

public class MultiTenantPersistModule extends PersistModule {
...

@Override
protected void configurePersistence() {
bind(PersistService.class).to(MultiTenantPersistServiceImpl.class);
ThrowingProviderBinder.create(binder()).
bind(EntityManagerFactoryProvider.class, EntityManagerFactory.class).
to(MultiTenantPersistServiceImpl.class);

bind(UnitOfWork.class).to(MultiTenantUnitOfWorkImpl.class);
ThrowingProviderBinder.create(binder()).
bind(EntityManagerProvider.class, EntityManager.class).
to(MultiTenantUnitOfWorkImpl.class);

...

}

So, at last, my question.
What is the simpliest way to specify jpaUnitName at MultiTenantPersistServiceImpl depending on Repo (AbstractFirstDbRepo or AbstractSecondDbRepo )?

Thanks a lot.
--
You received this message because you are subscribed to the Google Groups "google-guice" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to