Cool. I will take a look at a test case / documentation PR sometime this coming week.
From the point of view of a consistent API, what do you think of the idea of deprecating the required= attribute and instead saying that every optional injection should be written as Optional<T> myInjection; ? It has the advantages of consistency and that it reuses Java API. It has the disadvantage of being a bit more verbose in many cases, and potentially burring the semantics... I'm by no means the kind to slather Optional<> all over the place-- anywhere other than a return type, it's usually a bad idea in my experience. I think injection is a bit special, however. In a sense, the type of an injected value is both a received type (from the POV of the injected code) for which Optional<> isn't a good idea, and a produced type (from the POV of the framework) for which it is at least a reasonable choice, so I don't think it's totally crazy to turn to Optional<> in this circumstance, although I admit it's a bit strange. We see a similar pattern in the javax.enterprise.inject.Instance<> type, but that pre-dates Optional<> and is additionally responsible for providing access to multiple potential values for injection. Maybe Tamaya should support @Inject Instance<MyType> for optional config values in order to fit better with extant API? ajs6f > On Oct 19, 2018, at 9:38 AM, Anatole Tresch <[email protected]> wrote: > > yep. > > ajs6f <[email protected]> schrieb am Fr., 19. Okt. 2018, 13:25: > >> Thanks! To be clear, the behavior should be: >> >> required=false does _not_ work for CDI, because of underlying constraints. >> >> Optional<T> _does_ work with CDI, as an alternative. >> >> Correct? >> >> ajs6f >> >>> On Oct 19, 2018, at 4:02 AM, Anatole Tresch <[email protected]> wrote: >>> >>> Writing a test case would be awesome. Good travels! Anatole >>> >>> ajs6f <[email protected]> schrieb am Fr., 19. Okt. 2018, 02:11: >>> >>>> Glad to: https://issues.apache.org/jira/browse/TAMAYA-358 >>>> >>>> I hope that is clear-- let me know if not. I can try to write a test >> case. >>>> (Traveling for the next week or so, so after that.) >>>> >>>> ajs6f >>>> >>>>> On Oct 18, 2018, at 7:56 PM, Anatole Tresch <[email protected]> >> wrote: >>>>> >>>>> I consider this is a bug, can you file one ? Would be awesome ! >>>>> >>>>> Am Fr., 19. Okt. 2018 um 01:04 Uhr schrieb ajs6f <[email protected]>: >>>>> >>>>>> I'm afraid that didn't quite work (no change in behavior). >>>>>> >>>>>> Did I correctly understand you to mean this? >>>>>> >>>>>> @Inject >>>>>> @Config(value = { "trellis.configFile", "TRELLIS_CONFIG_FILE" }) >>>>>> private Optional<File> configFile; >>>>>> >>>>>> I've also tried it with required=false: >>>>>> >>>>>> @Inject >>>>>> @Config(value = { "trellis.configFile", "TRELLIS_CONFIG_FILE" }, >>>>>> required = false) >>>>>> private Optional<File> configFile; >>>>>> >>>>>> with the same behavior... >>>>>> >>>>>> ajs6f >>>>>> >>>>>>> On Oct 18, 2018, at 6:02 PM, Anatole Tresch <[email protected]> >>>> wrote: >>>>>>> >>>>>>> the problem is that CDI dies not support optional values in this way, >>>>>> this >>>>>>> works in a non cdi env e.g. Spring, osgi.... What should work is >>>>>> injecting >>>>>>> an Optional<File>. >>>>>>> >>>>>>> ajs6f <[email protected]> schrieb am Do., 18. Okt. 2018, 17:51: >>>>>>> >>>>>>>> Hi, Tamaya folks! >>>>>>>> >>>>>>>> I just tried using the required=false attribute of >>>>>>>> o.a.t.inject.api.Config, on a field, with a CDI project, a la: >>>>>>>> >>>>>>>> @Inject >>>>>>>> @Config(value = { "trellis.configFile", "TRELLIS_CONFIG_FILE" }, >>>>>> required >>>>>>>> = false) >>>>>>>> private File configFile; >>>>>>>> >>>>>>>> Unfortunately, it didn't seem to make the value truly optional. I >> got >>>>>> the >>>>>>>> expectable: >>>>>>>> >>>>>>>> org.apache.tamaya.ConfigException: Cannot resolve any of the >> possible >>>>>>>> configuration keys: [trellis.configFile, TRELLIS_CONFIG_FILE]. >> Please >>>>>>>> provide one of the given keys with a value in your configuration >>>>>> sources. >>>>>>>> >>>>>>>> Is required=false supported in that position, or am I >> misunderstanding >>>>>> its >>>>>>>> semantics? >>>>>>>> >>>>>>>> Thanks! >>>>>>>> >>>>>>>> ajs6f >>>>>>>> >>>>>>>> >>>>>> >>>>>> >>>>> >>>>> -- >>>>> *Anatole Tresch* >>>>> PPMC Member Apache Tamaya >>>>> JCP Star Spec Lead >>>>> *Switzerland, Europe Zurich, GMT+1* >>>>> *maketechsimple.wordpress.com <http://maketechsimple.wordpress.com/> * >>>>> *Twitter: @atsticks, @tamayaconf* >>>>> >>>>> *Speaking at:* >>>>> >>>>> [image: JSD_Speaker_2017][image: J-Con 2017 logo][image: JVM Con] >>>> >>>> >> >>
