
Explore the fundamentals of dependency injection and its role in Android app architecture, from manual dependency injection to Dagger and Hilt, with hands-on exercises and real code refactoring.
Learn dependency injection terminology, including the client and service relationship, contextual roles, and how to obtain dependencies—instantiate, static methods, global variables, or external injection in a singleton pattern.
Explore the three fundamental dependency injection techniques: constructor injection, method injection, and field or property injection, with practical Android Studio demonstrations.
Compare constructor, method, and field injections; constructor injection is simplest and most explicit, while method and field injections address late availability and framework constraints such as activities and fragments.
Explore dependency injection beyond constructor and field injection, examining puzzlers about encapsulation and internal data structures within large-scale architecture.
Understand how architectural patterns differ from design patterns and explore popular patterns like MVX, publish-subscribe, and event-driven architecture, including how architecture and patterns combine in apps.
Explore the dependency injection architectural pattern, separating an app into a functional set and a construction set that are disjoint and wired by glue logic, manifestation of separation of concerns.
Explore practical dependency injection in a real Android app by building a tutorial application that fetches latest Stack Overflow questions, displays a pull-down to refresh list, and navigates between screens.
Clone the tutorial application's source code from GitHub to your local machine, then use git commands like clone, log, reset, and reflog to navigate commits and history.
Review the tutorial Android app code, highlighting coroutine-based data loading, Retrofit calls to the StackOverflow API, and RecyclerView navigation between list and details for Dagger and Hilt dependency injection.
Extract the user interface logic from the questions list activity into a standalone mvc view. Delegate refresh and item click events to the listener.
Refactor the question details activity on a new git branch, review and reset to the targeted commit, then refactor in Android Studio and return to master to practice dependency injection.
Refactors question details and list views into a common base view mvc, extracting the observer design pattern and shared properties to remove code duplication while preserving functionality.
Extract networking logic from the questions list activity into a fetch questions use case, encapsulating retrofit initialization and the StackOverflow API calls, and return a domain result.
Refactor the networking logic from the questions list and details screens into a standalone use case object, then practice the same refactoring via an offline git exercise.
Refactor dialogs into a dedicated Dialogs Navigator, injecting a fragment manager to delegate server error dialogs, reducing dependencies, avoiding duplication, and increasing maintainability across screens.
refactor navigation into a screens navigator to decouple question list from details, enabling easy future refactors to single-activity or fragment architectures and centralized destination management.
Explore the model view controller pattern in Android, where the questions list activity is the controller and the fetch questions use case acts as the model.
Inject a single retrofit instance into use cases via the application class, avoiding duplication and improving performance when accessing the Stack Overflow API.
Remove retrofit as a global proxy by moving StackOverflow API to constructors and exposing it from the application class, reducing duplication and making clients depend only on StackOverflow API.
Learn the law of Demeter, a rule of least knowledge for dependencies; refactor to depend only on needed classes and talk to your immediate friends for cleaner, maintainable code.
Refactor the questions list activity to follow the law of Demeter by exposing the fetch questions use case from the application class, reducing direct dependencies on StackOverflow API.
Refactor the question details activity to remove its dependency on the StackOverflow API and the fetch question details use case construction, completing exercise three by resetting git history.
Refactor into an app composition root to centralize service instantiation and expose global objects like retrofit and stack overflow API, improving maintainability and dependency management.
Delay initialization of global services like Retrofit and the Stack Overflow API using lazy delegation to reduce startup time. This approach caches services after first use and keeps code simple.
Refactor screens navigator into an activity-scoped composition route and introduce an activity composition route alongside the app composition route, using lazy initialization to preserve lifecycle boundaries and clean abstractions.
Extract the dialogues navigator instantiation from activities into a composition route, and clarify the distinction with the activity composition route while obtaining the fragment manager and passing arguments.
Extract the dialogues navigator from activities into a composition route, choose the activity composition route due to fragment manager scope, and use a gateway to obtain the support fragment manager.
Explore how runtime arguments like the parent view group complicate dependency construction, refactoring an activity to a fragment, and sharing an activity-scoped composition route in Android.
Extracts mvc views construction logic into a factory to handle a runtime container view group, enabling instantiation of questions list view mvc via a view mvc factory and layout inflator.
Extract the creation of the question details view mvc into a view mvc factory and remove the law of Demeter violation from the question details activity, completing a simple exercise.
Introduce a presentation composition root to decouple presentation concerns from activity and app composition roots, organize services, apply lazy initialization, and improve maintainability and clarity of dependency scopes.
The refactored tutorial app clarifies the questions list fragment by exposing its responsibilities via a composition route, aligning with dependency injection and improving readability.
Explore pure dependency injection in Android, showing how to implement without frameworks by separating construction and functional sets through refactoring, and understanding core concepts.
Discover how dependency injection centralizes object creation in a single composition route. It exposes the complete object graph to clients and enables easy reuse.
Explore how dependency injection, through an Android-specific composition root hierarchy, prevents leaking activity context by restricting access to activity from app-scoped objects and using app context when needed.
This lecture clarifies the distinction between objects and data structures, showing that dependency injection concerns objects that expose behavior while data structures merely hold data, guided by composition rules.
Refactor with a dedicated injector to inject dependencies from outside, illustrating pure dependency injection while clarifying that this remains dependency injection rather than a service locator.
Explore convention over configuration in dependency injection, using a service annotation and reflection to inject private fields. Assess Android performance costs and how this convention leads toward DI frameworks.
Explore how dependency injection frameworks, as external libraries, provide templates for the construction set and predefined conventions, enabling integration with the functional set in Android apps, including Dagger 2.
Discover Dagger 2 as the official Android dependency injection framework from Google, its move from Dagger Android to Dagger Hilt, and master its conventions to simplify dependency injection.
This lecture refactors the presentation composition root into a dagger presentation module and component, showing how @Module and @Provides wire dependencies and how dagger generates the component.
Refactor activity and app composition routes to Dagger conventions via a two-step process, turning them into activity and app modules and components, and replacing module dependencies with component dependencies.
Learn how Dagger scopes govern dependency lifetimes by defining an activity scope and an app scope, and applying them to modules and components.
This lecture refactors dependency injection with Dagger conventions, turning the presentation component into an injector, removing custom injector and annotations, and using the inject annotation for code-generated injection.
Understand how dependent components in dagger and hilt enable sharing services between activity and presentation modules, using dependencies directive to access exposed bindings without re-providing them.
Refactor the Android dependency graph by making the activity component depend on the app component and remove redundant providers from the activity module, following the presentation component approach with Dagger.
Learn how subcomponents replace dependent components in a Dagger and Hilt setup, enabling presentation components to access parent services like StackOverflow API via a factory-driven subcomponent.
Refactor the dependency injection setup by making the app component the parent and the activity component a subcomponent, enabling the presentation component to receive its needed services.
Dagger allows a component to depend on multiple modules, sharing the same object graph, and can instantiate modules with no-argument constructors while bootstrapping dependencies are supplied for others.
Compare automatic service discovery with explicit provider methods in modules for Dagger and Hilt, highlighting scoped services and the value of keeping them in a single module for easy review.
Demonstrate the Dagger workflow by wiring a user image and name into the question details screen, using a Glide image loader and Dagger injected dependencies.
Dagger 2 replaces reflection with annotation processing, introducing components, modules, and scopes to clarify dependency injection conventions and accelerate integration in Android apps.
Learn to extend dependency injection to android services and dialogues by building service components and modules, wiring context via a base service, and a base dialogue within the presentation layer.
Explore how static provider methods via Kotlin companion objects improve Dagger-generated code performance, and how component builders and bind instances bypass modules for bootstrapping dependencies.
Explore how Dagger binds maps an interface to its implementation, using a screens navigator example and a companion object for static providers. Understand activity scope and binding nuances.
Learn how qualifiers distinguish multiple retrofit instances in Dagger and Hilt, and why custom qualifiers beat named for readable dependency injection; discover using a URL provider to avoid data-structure injections.
Learn how dagger's providers convention creates provider wrappers to fetch services from the object graph, preserving scopes such as activity scope and enabling late injection in factories.
Explore how to work with the ViewModel architecture component, its integration with Dagger two dependency injection framework, and the special treatment ViewModels require in Android apps.
Demonstrate injecting a view model into an activity with dagger in android to fetch questions via a coroutine and expose live data, and show rotation recreating the view model.
Leverage a dedicated view model factory to construct and supply your view models via a provider, ensuring the same instance is retained across rotation through dependency injection.
Refactor view model factories to obey the law of demeter by injecting a provider. Delegate creation to Dagger, reducing duplicated constructor parameters and improving maintainability as view models grow.
Centralize ViewModel provisioning with a single factory that uses the model class to instantiate multiple ViewModels, handling Kotlin and Java class nuances and reducing boilerplate.
Explore dagger multibinding for mapping multiple view models into a provider map. Keys use the view model class, enabling the factory to fetch the correct provider.
Learn to inject a saved state handle into Android view models using Dagger and Hilt. Wire save state registry owner through a presentation module to preserve data across process death.
Understand why ViewModels are complex, due to cross-cutting lifecycles and Demeter violations. The lecture critiques factory-based wiring, save state handle concepts, and advocates simplified dependency injection approaches.
simplify viewmodels by using a saved state viewmodel base and an init method, and implement dagger multi binding for a provider map to initialize them.
Explore Hilt, Google's wrapper around Dagger two, and learn how Hilt standardizes dependency injection in Android by using components, modules, and scopes to bridge construction and functional sets.
Align dependency injection with a component hierarchy, as Hilt's fundamental assumption does, including singleton, activity, activity retained, and ViewModel components with predefined scopes and default bindings.
Access the dagger hilt source code by switching to the dagger hilt branch, understanding Git branches and commits, and reviewing the final refactor from standard dagger to dagger hilt.
Set up hilt gradle dependencies for an android project, apply the hilt android plugin, use hilt android and hilt compiler, align dagger versions, then sync and refactor for hilt conventions.
Refactor a sample app from Dagger components to Hilt by removing app, activity, and presentation components, and use Android entry point annotations to inject dependencies into activities and fragments.
Discover how Hilt injects dependencies behind the scenes through Android entrypoint annotations, wiring implicit components like singleton and activity components during application onCreate and activity onCreate (fragments onAttach).
Learn how to install modules into Hilt components with install in annotations, use singleton and activity components, and resolve bootstrapping and scope issues for viewmodels.
Learn how Hilt scopes work, align modules with component scopes, and use scope aliases to map a custom app scope to the singleton scope, avoiding cross-scope errors.
Explore why Hilt cannot provide AppCompatActivity and how casting an activity to AppCompatActivity with a provides method enables fragment manager and layout inflator bindings, with a preview of ViewModel challenges.
Learn how Hilt simplifies viewmodel injection by replacing the viewmodel factory with direct constructor injection, enabling save state handle and using the by viewModels delegation.
Extend dagger with Hilt's conventions to standardize implicit components and scopes for smoother bootstrapping. Recognize added complexity, annotation processing, and potential build-time slowdowns.
In this course you'll learn all about Dependency Injection in Android and master Dagger and Hilt Dependency Injection frameworks. By the end of the course, you'll acquire an expert-level knowledge and will be ready to use Dagger, Hilt or manual Dependency Injection in your own Android applications.
A set of carefully designed, hands-on exercises will help you solidify your knowledge and allow you to practice using Dependency Injection in a controlled environment.
This course puts emphasis on professional, pragmatic and time-tested techniques and best practices. All the material that you'll learn has been thoroughly tested and evaluated in real production Android applications. You can even copy large parts of the source code from the tutorial application to your own projects to spare yourself much time and headache.
Professional grade
From fundamentals to best practices
Non-trivial examples
Hands-on exercises
Tutorial Android application on GitHub with step-by-step commits history for easier review
Many developers spend weeks learning Dagger, but, unfortunately, some still give up in the process. This course will make your learning journey more efficient and enjoyable, ensuring that you acquire these valuable skills, which are in exceptionally high demand in the Android industry.
So, if you want to learn Dependency Injection, Dagger and Hilt to develop clean and maintainable Android applications - this course is for you.