Skip to content

Bind interface to implementation without boilerplate #354

@vaughandroid

Description

@vaughandroid

Sometimes, for architectural reasons, I have interfaces with only one concrete class implementing them. Writing @Provides methods for these cases can involve a lot of boilerplate, especially if the constructor has a lot of dependencies.

e.g.

@Provides
@ActivityScope
public FavouritesListContract.Presenter provideFavouritesListPresenter(FavouritesClient favouritesClient,
        SearchStorage searchStorage, SettingsStorage settingsStorage, GoogleAnalyticsHelper googleAnalyticsHelper) {
    return new FavouritesListPresenter(favouritesClient, searchStorage, settingsStorage, googleAnalyticsHelper);
}

As long as the concrete implementation has an @Inject constructor it ought to be possible to just bind the class to the interface.

My thinking is that the binding still belongs in a Module. Perhaps a list of bindings could be provided in the @Module annotation?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions