you are in control of ViewHolder creation in your ...
# dagger
t
you are in control of ViewHolder creation in your adapter so you should use constructor injection
p
Is it possible to partially inject a constructor, because one of my parameters is the data I want bound to my RecyclerView
t
@peasee not sure I follow. IMO the view holder shouldn’t know about the data at all. should just be a passive view with a bunch of methods on it to help populate it with the data. then you have the adapter get the data and call the appropriate methods on the view holder. really the only thing the view holder should be getting passed in is the
itemView
. again all of this is my opinion, doesn’t make it right but can help keep it simple and separated in an arguably reasonable way.
p
@trevjones Sorry I meant my data is a parameter of the the adapter, Yeah atm the constructor of my view holder is
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
Would that be possible to use constructor injection on?
t
yea it is possible but because viewholders are recycled you should avoid having any domain state explicitly contained in them.
p
I see, thanks for the info 🔺