Skip to content

Instantly share code, notes, and snippets.

@maydin
Created November 12, 2016 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maydin/63649c6f82a3b59833e8b0c0d8029339 to your computer and use it in GitHub Desktop.
Save maydin/63649c6f82a3b59833e8b0c0d8029339 to your computer and use it in GitHub Desktop.
Dagger component and module
@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