avaje / avaje-inject

Dependency injection via APT (source code generation) ala "Server-Side Dagger DI"
https://avaje.io/inject
Apache License 2.0
227 stars 21 forks source link

Adds new SPI Annotation #622

Closed SentryMan closed 2 months ago

SentryMan commented 2 months ago

Trying to auto-register services with avaje-spi is a dead end. So I suppose we need to make spi annotation for the generators.

SentryMan commented 2 months ago

Feel free to change the names of the annotations to something else

rob-bygrave commented 2 months ago

Trying to auto-register services with avaje-spi is a dead end.

Why? What has gone wrong?

SentryMan commented 2 months ago

Trying to auto-register services with avaje-spi is a dead end.

Why? What has gone wrong?

I thought it was good too, but it has a fatal flaw in that if multiple annotation processors try to use this, not all of the processor's spi interfaces will get registered. The reason is that the spi processor must be the last processor to execute after processing is over.

Trying to wrangle the apt order causes more work, not less.

rob-bygrave commented 2 months ago

So I suppose we need to make spi annotation for the generators.

Or not? In that there are several options to consider now right?

What we know is that we need the inject-generator AP to write it's META-INF/services and not delegate that to avaje-spi-service (due to unknown ordering of the APs). Now if inject-generator AP appends to META-INF/services (and does not override) then this allows traditional manual registration of any InjectExtension. Does that not work?

SentryMan commented 2 months ago

Does that not work?

that's what #621 is for. This one is because I don't like manually writing services and avaje-spi can't be used to automate this

rbygrave commented 2 months ago

that's what https://github.com/avaje/avaje-inject/pull/621 is for.

Yes, got that now. I saw the emails and saw the "Trying to auto-register services with avaje-spi is a dead end." ... so I came here first (so yeah I missed the previous part of the story there).

SentryMan commented 2 months ago

hmm, an alternate strategy would be to annotation process the avaje-spi @ServiceProvider and modify avaje-spi-service such that it'll abort writing any of the spis claimed by our generators

rob-bygrave commented 2 months ago

It is generally the case for avaje-inject that the only folks registering a service will be InjectPlugin authors right? Like there might be better cases like avaje-validation but its not got good bang for buck here for avaje-inject as I see it.

SentryMan commented 2 months ago

It is generally the case for avaje-inject that the only folks registering a service will be InjectPlugin authors right?

Even so, writing services is tedious. In any case, don't forget those who may want to use the Property Plugin spi or fiddle with custom module ordering logic.