Coder Social home page Coder Social logo

dagger-codelab's Introduction

Dagger-Codelab

Codelab to teach and demonstrate usage of dependency injection with Dagger 2

CircleCI

What you will learn

  • About dependency injection(DI) and Inversion of Control(IoC)
    • Introduction to the problem, why it matters.
    • Why we use DI frameworks - which problems they solve for us.
    • Brief history of DI. Spring -> Guice -> Dagger 1 -> Dagger 2
      Initial presentation slides
  • Basics of Dagger
    • How to setup Dagger in your project.
    • How to use @Inject annotation, creating simple @Component
    • Adding @Module. Discussion when to use modules and when @Inject annotation.
    • Usage of simple @Singleton scope.
    • Exploring Dagger generated source code and learning from it.
  • Wiring together with Android
    • Where to create and hold instances of components.
    • Injecting Activities, Injecting Fragments.
    • Using @BindsInstance to bind objects we don't own.
  • Multi-module project setup
    • How to compose modules together within AppComponent
    • Injecting Activity/Fragment and other dependencies within separate module.
    • Sharing instances with other modules.
  • Multibindings
    • Composing @IntoMap and @IntoSet.
    • Plugin based development within multi-module project.
    • Discuss which problems can multibinding solve.
  • Instrumented Testing
    • How to replace dependencies within androidTest.
    • Using separate component to replace dependencies in tests.
    • How to assert on your analytic events.
  • Dagger Hilt migration
    • Setting up Dagger Hilt in the project.
    • How to Migrate project to Hilt
  • Instrumented testing with Dagger Hilt
    • Setting up testing in project.
    • Replacing dependencies in tests
    • Discussing Hilt pros and cons.

Why this codelab?

  • Primarily this should be a learning resource for any engineer who wants to learn or recap Dagger usage.
  • The codelab format is chosen with the belief, that first hand experience leaves stronger memories and the skills are truly learned.
  • Dagger became more complex over years - making onboarding of new engineers harder.
  • Dagger became also misused or overused. New engineers see already brownfield and Dagger seems like one of the devils responsible for this leading to lower trust in the tool. Dagger can be almost invisible in your project.
  • We already forgot about the problems we had before Dagger like runtime DI resolution. It is important to be reminded about these problems.

How to use this Codelab

  • Codelab is split into few smaller sections - each of them can be run independently.
  • Each section has a branch with a format {section number}-{area of focus} e.g. 01-basics. The branch with higher number is always the solution of the previous section. master branch is the final solution of present tasks.
  • You can run the codelab yourself, by following the instructions within each sections.
  • In case of any question, please feel free to create an issue in this repo.

Now let' start by moving to section you want

Dagger Hilt Option

If you would like to see how would the current project look like in Dagger Hilt check the extra exercises:

With solution at 08a-hilt-option-solution

References

dagger-codelab's People

Contributors

alejandrorosas avatar jraska avatar vladad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dagger-codelab's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.