@AddAccessor annotation to automate accessor creation for included graphs #752
bubenheimer
started this conversation in
Ideas
Replies: 1 comment 2 replies
-
I'm not a fan of this on the face of it as it conflates the purpose of providers and seems like a niche use-case. It would also be quite non-trivial to implement due to the nature of how FIR works (there is no notion of processing rounds that would allow generation of new declarations). Using KSP seems like the right approach for this. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'd like to propose a new annotation for Metro, for now let's call it
@AddAccessor
. The annotation would trigger addition of a public accessor in a dependency graph.An oversimplified example:
This would result in something like this being generated:
This is useful for included graphs (a.k.a. Dagger’s component dependencies): only public accessors from the included graph are available as bindings in the including graph.
Without this annotation there can be a lot of boilerplate for adding public accessors when there are a lot of desired bindings in the included graph.
From my perspective the annotation is a natural next step for dealing with included graphs, so I believe it’s of general value.
I have this implemented as a custom Anvil processor. Would be nice to get it integrated into Metro natively, to avoid the slow KSP route and make it more widely available.
The gist of the Anvil annotation is this:
It’s repeatable, because graphs can be included “recursively”, so more than one level of included graph may need to expose the accessor. (If this sounds too unconstrained, 99% of my cases do not need
@Repeatable
or specifying a scope explicitly, and just use the default scope approach below, so it would be ok to just add a bit of manual work for the remaining 1%.)The Anvil processor generates a custom interface plus
@ContributesTo
to include it in the graph.There is a little more design detail I can add if this proposal finds support. In particular, the explicit scope can be omitted when it is clear from the context, i.e. a
@ContributesTo
on an enclosing element, which is the common case.This could possibly also be an alternative approach for contributed graph extensions.
Here is a more comprehensive example:
Beta Was this translation helpful? Give feedback.
All reactions