Skip to content
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

inject repository using hilt #33

Merged
merged 2 commits into from
Apr 12, 2024
Merged

Conversation

violoncelloCH
Copy link
Member

@violoncelloCH violoncelloCH commented Apr 2, 2024

based on #32
requires #32 to be merged first done

this allows to use use the main repository implementation without passing it manually

@violoncelloCH violoncelloCH self-assigned this Apr 2, 2024
@violoncelloCH violoncelloCH force-pushed the feature/repository-injection branch from fe4f2fd to eb7d459 Compare April 2, 2024 20:13
@violoncelloCH
Copy link
Member Author

violoncelloCH commented Apr 2, 2024

@octogradiste I tried to add the dependency injection following what you've done in #26, but somehow it throws an error on the test. Do you have an idea where that comes from?

Error log output
/home/runner/work/echo/echo/app/build/generated/hilt/component_sources/debugAndroidTest/dagger/hilt/android/internal/testing/root/Default_HiltComponents.java:136: error: [Dagger/MissingBinding] com.github.swent.echo.data.repository.Repository cannot be provided without an @Inject constructor or an @Provides-annotated method.
  public abstract static class SingletonC implements EchoApplication_GeneratedInjector,
                         ^
  
  Missing binding usage:
      com.github.swent.echo.data.repository.Repository is injected at
          com.github.swent.echo.di.DependencyInjectionTest.repository
      com.github.swent.echo.di.DependencyInjectionTest is injected at
          com.github.swent.echo.di.DependencyInjectionTest_GeneratedInjector.injectTest(com.github.swent.echo.di.DependencyInjectionTest)

the original CI run can be found on #28 (this PR here is incomplete)

@violoncelloCH violoncelloCH mentioned this pull request Apr 2, 2024
@octogradiste
Copy link
Contributor

Hi, I checked out the code and the reason for the error is, hilt can't inject the Repository into the test because you have told hilt how to provide an IRepository but not how to provide a Repository. What you have done is correct! We want to tell hilt how to provide an interface, so that when we are coding the logic, we don't have to think about a concrete implementation but rather of an interface. To fix the error, you could change the type to IRepository inside the test...

But what I suggest is to change the naming of your interface to Repository and the implementation to RepositoryImpl. This is how I already did it for the AuthenticationService and I really like this convention. I think it avoids confusion for the one using the interface. In this case, it actually confused you too. :)

@octogradiste
Copy link
Contributor

octogradiste commented Apr 5, 2024

Note that the renaming will also affect #32 and #30

@violoncelloCH
Copy link
Member Author

Ohh thanks, now I get it!
Well for me the confusion was actually the other way round. I'm used to the convention of having the interfaces prefixed by I. So when looking at you have done the test, I actually thought you were passing in the implementations and not the interfaces 🙃 . For me the prefixing with I actually makes a lot of sense especially in situations like these where we have only one implementation anyways. Also, we have got other classes where there just is no interface, so in these cases we also do not suffix them with Impl.
But in the end I guess it's just a matter of conventions and of course it makes sense to choose one of them. Not sure if that's worth to quickly discuss with everyone to vote on what the majority prefers?

@violoncelloCH violoncelloCH force-pushed the feature/repository-injection branch 3 times, most recently from f1f3a21 to e3ccb29 Compare April 12, 2024 11:55
Signed-off-by: Jonas Sulzer <jonas@violoncello.ch>
Signed-off-by: Jonas Sulzer <jonas@violoncello.ch>
@violoncelloCH violoncelloCH force-pushed the feature/repository-injection branch from e3ccb29 to b92cc48 Compare April 12, 2024 12:18
@violoncelloCH violoncelloCH marked this pull request as ready for review April 12, 2024 12:20
Copy link

Copy link
Contributor

@octogradiste octogradiste left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for adding this!

@octogradiste octogradiste merged commit 7a2b701 into main Apr 12, 2024
2 checks passed
@octogradiste octogradiste deleted the feature/repository-injection branch April 12, 2024 12:42
@violoncelloCH violoncelloCH added this to the Milestone 1 milestone Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done in sprint 3
Development

Successfully merging this pull request may close these issues.

2 participants