-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RequiresBean and RequiresProperty Annotations #312
Conversation
|
To me I'm almost certain this is a copy of the equivalent spring feature and their string name matches to a full type name ... and we need to use the string rather than |
As some background, as I see it IF the "conditional" in practice translates to ... "wire these 10 beans based on this 1 condition" then custom scopes are a good fit. IF the "conditional" in practice translates to ... "wire this 1 bean based in this 1 condition" then yes For me, the custom scopes case is the common one I have seen in practice although the good alternative would have been to use a |
It was pretty late when I wrote this so I guess I was unclear.
well looks like I goofed, I somehow totally misinterpreted how the beanScope
Oh, this PR does that too, it's why I changed the factory methods to use getNullable.
|
I think this "name" area is confusing because Spring DI really does give beans a "name" (not just a qualifier) and that "name" is based on the class short name (TLDR Today this looks like a terrible idea). This was maybe a good idea way back in the day with xml wiring configuration and only a few beans being wired but imo its a terrible idea when we might be wiring hundreds of beans in a large multi-module application because using the class short name is prone to not being unique - its easy for a bean with a completely different type to override another. Both Micronaut and avaje-inject both do NOT follow Spring DI here with respect to "bean name" and both only using Qualifier + Type. Depending on who we talk to "name" can be a confusing term and as you say we note For myself, I'm thinking I should try and just talk about "Qualifier" and Type (and not use "name" anywhere - the Note that Micronaut uses |
ok I can rename |
ah hang on, I'm inspired now |
I think I'll split requires into two, one for beans and another for properties. The Micronaut one that is |
I'm also going to use |
Okay, @rbygrave how's this? |
Generated class
|
Hmm, using |
I haven't used custom scopes all that much, but say you're building an auto-configuration library using avaje, with a bunch of beans only supposed to be wired based on a bunch of separate conditions for multiple beans, I'm thinking using custom scopes would become a little unwieldy. |
I mean the kiwi bird/fruit gag was pretty funny, but we don't need all those test classes
In any case, I think I got it working how I want. Please review when you get time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have a look at these points but looking really good.
Maybe the main thing is that I think we should add a new interface like RequiredPropertiesPlugin that has our 3 property checking methods and can implement that via Config or via System properties (or someone can put in their own implementation).
inject-generator/src/main/java/io/avaje/inject/generator/MethodReader.java
Outdated
Show resolved
Hide resolved
inject-generator/src/main/java/io/avaje/inject/generator/MethodReader.java
Outdated
Show resolved
Hide resolved
inject-generator/src/main/java/io/avaje/inject/generator/BeanReader.java
Outdated
Show resolved
Hide resolved
inject-generator/src/main/java/io/avaje/inject/generator/BeanReader.java
Outdated
Show resolved
Hide resolved
blackbox-test-inject/src/main/java/org/example/myapp/conditional/BirdFactory.java
Show resolved
Hide resolved
…t into SentryMan-conditionalOnBeans
With a default implementation using System Properties
We never expect to register null or Optional empty.
The follow up PR is - #315 |
Nice, don't have access to modify that one so I'll pull it over here and add on to it |
Groovy. I think we merge this in and tweak in master (add javadoc etc) |
- Read the repeatable Container annotations - Move the annotation reading into BeanConditions - Rename the inner repeatable annotations to Container (so IDE autocompletion for Requires* only sees our 2 @RequiresBean and @RequiresProperty annotations
contains
methodsOptional.empty()
beansI'm thinking this is a good idea. Will not try to wire the bean if the condition is not met. This used in conjunction with
@Secondary
could be handy.Generated proxyConfig factory method