Git Product home page Git Product logo

Comments (10)

svenjacobs avatar svenjacobs commented on April 28, 2024 11

@gk5885 Now both #73 and #102 are closed. Where do we further discuss this issue?

from dagger.

konmik avatar konmik commented on April 28, 2024 2

Here is my solution for injection through a base class:

https://github.com/konmik/Dagger2Example/blob/master/app/src/main/java/info/android15/dagger2example/Dagger2Helper.java

from dagger.

mgrzechocinski avatar mgrzechocinski commented on April 28, 2024

Yep, always faced it, but somehow blindly accepted it.

Worth mentioning, that in Child->Parent direction it works. In your component you only need inject(ChildActivity). Then, you can call inject from child activity only and parent activity's fields would also be injected.

Samples: ChildActivity and ParentActivity and Component

from dagger.

Dorvaryn avatar Dorvaryn commented on April 28, 2024

@mgrzechocinski Yeah it works fine on the Child -> Parent direction.
Unfortunately I find the Parent -> Child situation a lot more common (ie Parent Activity define Injection and Children can use the @Inject if needed.)

I'm now using the Parent Activity as a hub and provide accessors to the injected fields. It seems to be the less boilerplate I can find for that situation.

In the short term if this cannot be resolved the example should be changed as it is not working.

from dagger.

artem-zinnatullin avatar artem-zinnatullin commented on April 28, 2024

This is an old thing from Dagger 1...

My dirty solution: use some static DIContainer inner class in super class which holds injected things required for children.

But it will be great if issue will be resolved

from dagger.

tbroyer avatar tbroyer commented on April 28, 2024

This is a dupe of #73

from dagger.

chrisjenx avatar chrisjenx commented on April 28, 2024

@Dorvaryn I expose an protected abstract Inject() method on the parent which the child has to implement, this is to encourage the correct implementation in your children.

I guess there could be a warning here?

from dagger.

cgruber avatar cgruber commented on April 28, 2024

We'll take a look at the examples - it's entirely possible that it's not a valid example anymore, as it was raw-ported without a lot of thought.

from dagger.

konmik avatar konmik commented on April 28, 2024

You're right, this solution is quick and dirty just to show how this could be done. It does not throw informative exceptions and does not have tests. Naming and architecture could be better.

from dagger.

gk5885 avatar gk5885 commented on April 28, 2024

IIUC, @tbroyer was correct and that this is a dup. So, I think we can just call this closed.

from dagger.

Related Issues (20)

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.