Comments (10)
@gk5885 Now both #73 and #102 are closed. Where do we further discuss this issue?
from dagger.
Here is my solution for injection through a base class:
from dagger.
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.
@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.
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.
This is a dupe of #73
from dagger.
@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.
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.
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.
IIUC, @tbroyer was correct and that this is a dup. So, I think we can just call this closed.
from dagger.
Related Issues (20)
- Optional bindings in a parent component can sometimes use bindings from child components HOT 2
- NullPointerException dagger.spi.shaded.androidx.room.compiler.processing.XTypeElement.getAnnotation HOT 6
- Problem with Injection of DAO HOT 1
- error: [Hilt] Could not get element for com.foo.viewModels.FooViewModel_HiltModules.BindsModule: java.lang.NullPointerException HOT 1
- Missing release notes for 2.51 HOT 1
- `LazyClassKey` doesn't work when providing a `Map<Class<*>, Provider<?>` with a scope
- @AssistedInject in ViewModel using Dagger (NOT Hilt, just dagger) does not compile: cannot be provided without an @Inject constructor or an @Provides-annotated method HOT 6
- [issue] Dagger doesn't compile or doesn't give a right error message when ViewModelFactory is implemened on Kotlin rather than on Java HOT 4
- Having an issue with Dagger Hilt Proguard Rules HOT 12
- Following dagger.dev tutorial doesnt create singleton in v2.51 HOT 2
- Multibinding with Nested Complex Keys uses the wrong AnnotationCreator HOT 1
- [Hilt] onCreate() in my Application doesn't called on Instrument test HOT 4
- [Dagger-Hilt] Error when applying obfuscation other than Proguard (Allatori) HOT 3
- error: [Hilt] Expected @AndroidEntryPoint to have a value HOT 3
- @IntoSet analog for injectable classes HOT 3
- Hilt Generated Code having not used code? HOT 2
- [Dagger-Hilt] Can't get viewModel in composable by Hilt HOT 1
- Why does Provides in a Companion Object work? HOT 5
- Update Dagger guava dependency to address CVE-2023-2976 HOT 2
- Add KMP support for @HiltViewModel annotation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dagger.