Created
November 12, 2016 09:49
-
-
Save maydin/63649c6f82a3b59833e8b0c0d8029339 to your computer and use it in GitHub Desktop.
Dagger component and module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
@Component (modules={UserModule.class}) | |
public interface UserComponent { | |
void inject(MainActivity activity); | |
} | |
@Module | |
public class UserModule { | |
@Provides | |
@Singleton | |
UserService providesUserService() { | |
return new UserServiceImpl(); | |
} | |
} | |
public interface UserService { | |
String login(); | |
String logout(); | |
} | |
public class UserServiceImpl implements UserService { | |
public String login(){ | |
return "Logged in"; | |
} | |
public String logout(){ | |
return "Logged out"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment