Working with Hilt Modules

Learn how to use Hilt modules in Android.

Introduction

Hilt can be used for constructor-based dependency injection. However, we can’t use constructor-based DI in every scenarios. For example, if we create an instance of a class from an external library, constructor-based DI can’t be used. There are several other scenarios where this is the case. For these scenarios, the Hilt modules can be used for DI.

Defining a Hilt module

We’ll use an open-source country list API and create its instance using Hilt modules. To refresh our memory, let’s take a look at the CountryListInterface.

Get hands-on with 1200+ tech skills courses.