I have two repositories:
There are cases when the result of a call to the text repository requires access to the nodes repository, e.g.:
class TextRepository < Rom::Repository[:texts] def initialize(manager:, node_repository:, variant_builder: Model::Variant) super(manager.rom) @node_repository = node_repository @variant_builder = variant_builder @text_builder = Content end def by_node_ids(ids, variant=nil) query = texts.where(node_id: ids) query = query.where(variant_name: variant.compatible_variants) if variant query end def select(selector) nodes = @node_repository.select(selector) self.by_node_ids(nodes.map(&:db_id), @variant_builder.new(selector[:variant])).to_a end end
So far I have used manual dependency management, as you can see in the
initialize method. Yet recently I started using
dry-auto_inject and here lays the problem.
To make the NodeRepository available in the TextRepository I would have to declare the NodeRepository in the container and call
super in order for the dependencies to be auto-injected. Yet, on the other hand, the TextRepository inherits from Rom::Repository and I have to call
super with Rom instance. Those two scenarios are not going to work together. So, since I know that you (@solnic in particular) use dry-auto_inject with rom I would be happy to know the best solution for this kind of a problem.