-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 basic injection capabilities to QuarkusTestResourceLifecycleManager #18698
Comments
/cc @geoand |
Thanks for reporting! This seems pretty useful to me. Hopefully I can pick it up soon |
@FroMage always has exquisite API improvement ideas, so let's tap into his knowledge to get another take on this one :) |
My idea building on what @famod posted here is something like: default void inject(TestInjector testInjector) { // this is the new method
}
interface TestInjector { // the implementation will be supplied by the test extension and one new instance will be created per test - the instance will also hold the test object
void injectIntoFields(Object fieldValue, Class<?> fieldType);
void injectIntoFields(Object fieldValue, Class<?> fieldType, Class<? extends Annotation> annotation); // perhaps we don't need this method at all, and just make the previous one use varargs
} Then a supplied user implementations of @Override
public void inject(TestInjector testInjector) {
testInjector.injectIntoFields(this.someValue, SomeClass.class);
} WDYT? |
I like the varargs idea. CDI PS: Another strategy, which can be used today, is to define an interface with one or more setters etc. and then use the existing inject method that can then simply do an |
…ect into test Resolves: quarkusio#18698
#18714 is what I have in mind |
I like the idea but should be really clear that it has nothing to do with CDI injection ;-). |
@mkouba definitely. How do you propose we make it clearer? |
I'm not sure. Maybe just emphasize that the manager is fully in control of the lifecycle of the injected instance and that this "injection" happens after the CDI injection is perfomed?? |
…ect into test Resolves: quarkusio#18698
PR updated to include that note in the Javadoc and the documentation |
…ect into test Resolves: quarkusio#18698
…ect into test Resolves: quarkusio#18698
…ect into test Resolves: quarkusio#18698
…ect into test Resolves: quarkusio#18698
Provide easy way for QuarkusTestResourceLifecycleManager implementations to inject into test
…ect into test Resolves: quarkusio#18698 (cherry picked from commit 2be876f)
This is perfect! |
Description
As discussed on Zulip, it would come in handy if there was some convenient injection support in
QuarkusTestResourceLifecycleManager
.Today you are on own since you only get the
testInstance
ininject()
and you have to do all the hard reflection work yourself.Implementation ideas
In a backward-compatible way, a new
inject(BasicInjector injector)
method could be introduced.That
BasicInbjector
(or whatever its name is) wraps the test instance and could provide some basic convenience methods like:injectIntoFields(Class<?> type, Object value)
(or with<T>
)injectIntoFields(Class<? extends Annotation> type, Object value)
The text was updated successfully, but these errors were encountered: