Beginner questions related to the official tutorial

55 views
Skip to first unread message

Thomas Lehmann

unread,
Jun 3, 2021, 12:07:46 PM6/3/21
to Dagger Discuss

Hi,

what I'm basically have been looking for was a comfortable way of using a factory
where the factory does not know directly the implementation.

Main point is that in my project I have very strict rules from Checkstyle and
PMD complaining if one class does know too many others.

Now looking at the tutorial from your side - coming to my questions - I wondered
about at least two things:
  1. The whole thing does work only if I specify the list of modules at the component annotation. Is this not the opposite to what I mentioned about loosely coupled classes? At least from tutorial there is one module per command ... Isn't there a way to work without that?

  2. In the tutorial the command is created once and then used to route the input to that command. How to change that when I need a new command of same type for each routing operation? (in my case I have tasks being read from a document and I need the "new Task" instance mechanism on each task I find in the document depending on the type of task.
I think that it's for the beginning :)

Kind Regards,
Thomas

Ron Shapiro

unread,
Jun 6, 2021, 2:17:31 AM6/6/21
to Dagger Discuss
  1. @Modules.includes allows you to compose modules if that's what you're looking for. But be careful to make logical groupings; it's not necessarily an antipattern to have a long list of modules in your component. It's often easiest to think about groupings of modules once you start having multiple configurations/components.
  2. Instead of requesting a Map<String, Command>, you can request a Map<String, Provider<Command>>. Once you have the appropriate Provider<Command>, calling provider.get() multiple times will give you multiple instances.

--
You received this message because you are subscribed to the Google Groups "Dagger Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dagger-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dagger-discuss/2507b712-4c97-497b-b5b0-78bb2d7ab51fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages