-
Notifications
You must be signed in to change notification settings - Fork 645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Connect SDK] Update Connect example app to use Hilt dependency injection #9579
Conversation
Risky Change This is considered a risky change because it adjusts the sample app build.gradle, please review carefully. By adding the label |
Diffuse output:
APK
|
140896b
to
2361fcf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to not use the @Singleton
annotation?
) : ViewModel() { | ||
|
||
private val logger: Logger = Logger.getInstance(enableLogging = BuildConfig.DEBUG) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should add the logger to DI graph as well but can do in follow-ups.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We talked, I'll do this in a follow-up
import kotlinx.coroutines.launch | ||
import java.io.IOException | ||
|
||
@OptIn(PrivateBetaConnectSDK::class) | ||
class EmbeddedComponentManagerWrapper private constructor() { | ||
class EmbeddedComponentManagerWrapper( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class EmbeddedComponentManagerWrapper( | |
@Singleton | |
class EmbeddedComponentManagerWrapper @Inject constructor( |
|
||
class EmbeddedComponentService private constructor( | ||
private val settingsService: SettingsService = SettingsService.getInstance(), | ||
class EmbeddedComponentService @Inject constructor( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class EmbeddedComponentService @Inject constructor( | |
@Singleton | |
class EmbeddedComponentService @Inject constructor( |
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object ServiceModule { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is necessary if we use the @Singleton
annotation appropriately, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, I didn't realize this annotation existed. Much better, and yes we shouldn't need this module anymore!
class SettingsService private constructor(context: Context) { | ||
class SettingsService @Inject constructor(context: Context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class SettingsService private constructor(context: Context) { | |
class SettingsService @Inject constructor(context: Context) { | |
@Singleton | |
class SettingsService @Inject constructor( | |
@ApplicationContext context: Context | |
) { |
Summary
Integrate Hilt into the example app.
Motivation
The connect example app is getting more complicated, and integrating Hilt will make it faster (and less error-prone) to test.
Testing
I tested all of the flow (there aren't many of them) and tested that they still work + don't crash.
Screenshots
demo-1731098981.mp4