79733332

Date: 2025-08-12 14:41:06
Score: 2
Natty:
Report link

@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;
    }
Reasons:
  • Blacklisted phrase (1): StackOverflow
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @PrivateToDatabase
  • Low reputation (1):
Posted by: qba47