Hi everyone!
I'm trying to Inject my TransactionManagerProvider..
public class TransactionManagerProvider implements Provider<TransactionManager> {
@Inject
private DatabaseProvider databaseProvider;
@Override
public TransactionManager get() {
ConnectionSource connectionSource = databaseProvider.get().getConnectionSource();
return new TransactionManager(connectionSource);
}
}
where DatabaseProvider:
public class DatabaseProvider implements Provider<OrmLiteSqliteOpenHelper> {
@Inject
private Provider<Context> contextProvider;
@Override
public OrmLiteSqliteOpenHelper get() {
return OpenHelperManager.getHelper(contextProvider.get(), MyDatabaseOpenHelper.class);
}
}
But when I call it:
transactionManagerProvider.get().callInTransaction(new Callable<Void>() {
//call to daos methods and logic
}
I got an exception:
1) Error in custom provider, java.util.EmptyStackException
at roboguice.config.DefaultRoboModule.configure(DefaultRoboModule.java:130)
while locating android.content.Context
1 error
at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:987)
at it.cpmapave.mt.service.InterventoServiceImpl.synkInterventi(InterventoServiceImpl.java:109)
at it.cpmapave.mt.aservice.SynkService.onHandleIntent(SynkService.java:98)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:132)
at android.os.HandlerThread.run(HandlerThread.java:60)
Caused by: java.util.EmptyStackException
at java.util.Stack.peek(Stack.java:58)
at roboguice.inject.ContextScope$1.get(ContextScope.java:108)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:40)
at com.google.inject.internal.InjectorImpl$4$1.call(InjectorImpl.java:978)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1024)
at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:974)
... 6 more
But if I comment out the line that create the transaction and I run only the dao methods inside it works!
The problem as the exception states is that roboguice cannot access the Context.. But I don't know why the code inside transaction works.. the context is the same!
Maybe that code inside transaction works because the daos are created in an Activity context? and that the transaction don't work because the TransactionManager is created inside a Service context?
Thank you for your response..
Marco