Open mr746866 opened 6 years ago
@android10 Can you please shed some light on this?
Option 2 would be better. Not only it makes your functions generic (and reusable, when using different id as parameters), it also separates the concern. AuthManager is a "Manager" and not a repository. You may create something like SessionRepository to store session related data. and you can use that repository in the use case
@mr746866 Your other option is to create a custom scope... I call this my session scope, and in that scope I have my user model as a provided model, so I can inject it anywhere in my data layer which gives me acess to my userID and such, and as long as your data layer objects are scoped in the session graph they'll be able to inject the user modle... or you could even do @Named("userId") @Provides String userId
or something to that effect.
In my project, I need to fetch some data related to the authenticated user, and for that I need the
userId
of the user. I have anAuthManager
class that gives me theuserId
of the authenticated user. I am confused whether to add thisAuthManager
class as a member of myUserRepository
implementation, or just get theuserId
fromAuthManager
outside the repository and provide it when needed. Basically I have 2 options.Option 1: Add
AuthManager
as a member to theUserRepository
implementation.UserRepository
will contain functions likegetAuthenticatedUserFirstName()
,getAuthenticatedUserLastName()
etc. In the implementations of these functions use theAuthManager
to get the necessaryuserId
internally.Option 2: Leave out
AuthManager
from the repository.UserRepository
will contain functions likegetFirstName(String userId)
,getLastName(String userId)
etc. When calling these functions, use theAuthManager
to get the requireduserId
parameter.Looking for feedback and suggestions.