@PrivateToDatabase is a qualifier (thats missing from the docs).
The subcomponent module should have something like that:
@Module
public class DatabaseImplModule {
@Provides
@PrivateToDatabase
Database provideDatabase() {
return new Database();
}
}
If you want constructor injection, it won't work (StackOverflowError). You would need to pass arguments to new Database(arg1, arg2)
manually with new
.
On the other hand, field injection will work using members injector:
@Provides
@PrivateToDatabase
Database provideDatabase(MembersInjector<Database> injector) {
Database instance = new Database();
injector.injectMembers(instance);
return instance;
}