|
|
Re: @Optional resource not being injected [message #1062933 is a reply to message #1062622] |
Tue, 11 June 2013 13:07 |
Ezequiel Panepucci Messages: 4 Registered: June 2013 |
Junior Member |
|
|
hi Dirk,
Here is the documentation for "@Optional" which I rely on:
"
The @Optional annotation can be applied to methods, fields, and parameters to mark them as optional for the dependency injection. Typically, if the injector is unable to find a value to inject, then injection will fail. However, if this annotation is specified, then:
for parameters: a null value will be injected;
for methods: the method calls will be skipped;
for fields: the values will not be injected.
"
which means that a method annotated with @Optional will be skipped not executed regardless of its existence in the context.
But in any case; I have a field annotated with @Optional and the problem is that the resource *is* available because I can inject it in a view from the same application context.
The reason I annotate this resource with @Optional is because this piece of code can execute in different applications, some of them have the resource in question but others do not have it.
I thought that @Optional was meant for this scenario...
Is there a chance this is a bug in RCP Juno?
I'll try the beta kepler later and see if that works.
Thanks for the message.
Cheers,
Zac
|
|
|
|
Re: @Optional resource not being injected [message #1062955 is a reply to message #1062933] |
Tue, 11 June 2013 14:19 |
Eclipse User |
|
|
|
IIRC if your injection is optional than the injector will NOT auto-create the thing annotated with @Creatable. It will create it only if the injection is mandatory. If you annotate your method with @Inject @Optional then the DI container searches for an already created instance in the context hierarchy. If it is not found it says 'nevermind' and skips the method. When you annotate it just with @Inject, it creates the creatable POJO and invokes the method with the new POJO.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04121 seconds