-
Notifications
You must be signed in to change notification settings - Fork 17
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
DI - Adding basic manual injection #32
Conversation
testImplementation("io.mockk:mockk-android:1.13.9") | ||
testImplementation("io.mockk:mockk-agent:1.13.9") |
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.
Using Mockk for mocking objects. It's more modern and designed for Kotlin code.
More info:
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.
TIL about Mockk, thanks for the links
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.
Good first implementation but as we quickly grow the codebase we'll need to split GravatarSDKContainer into sub-containers (network, image loading, oauth flow, db, ...)
4a9c4ff
to
109f366
Compare
109f366
to
d886841
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.
LGTM
I didn't investigate Koin, but I'm pretty sure we could use it if we wanted.
Honestly I'd like to remove some boiler code (maybe by testing/using Koin), but I'd also like to avoid an extra dependency. So I'm fine using manual injection first, we can revisit this later if it becomes a pain to manage. Good thing, it won't impact the end users (developers) if we swap it with Koin.
#14
I did some research about DI in libraries. What I've seen is that, in general, libraries don't usually use another library for the DI. I would say there are two main reasons for that:
My first idea was to search for libraries using HILT. The short answer is: You can't use HILT in a library (If you don't fully control the app that is going to use the library at it also uses HILT, so it's not a valid solution for a public library).
Dagger is definitely a viable option. There is a limited amount of info on the internet, and I couldn't find several projects using it.
I didn't investigate Koin, but I'm pretty sure we could use it if we wanted.
Taking the previous info into account plus the expected side/complexity of our library, I think the best option for us is to use basic manual injection. Basically, to be able to implement good quality tests without. You can find a basic example here.
This PR follows the Google example and creates a test to verify the idea behind the manual injection.
Please, feel free to leave your comments. I'm opening the discussion about DI with this PR.