I want to make a UserScope with Dagger 2 that provides a User for several Activities. When the User log-in, Dagger inject the User to these activities, and once the User log-out, the instance must be null until the next log-in. this is what i did so far: the user scope:
@Scope
@Retention(RetentionPolicy.RUNTIME)
public @interface UserScope {
}
the user component:
Dagger generate error saying that BaseActivity should be a module
@UserScope
@Subcomponent(
modules = {
UserModule.class,
NetworkModule.class
}
)
public interface UserComponent {
UserComponent inject(BaseActivity activity);
}
and the UserModule
@Module
public class UserModule {
private User user;
public UserModule(User user) {
this.user = user;
}
@Provides
@UserScope
FirebaseUser provideUser() {
return user;
}
}
Should I make a Module activity for each activity that needs User ??