Willi,

I might get back to this. But there is one thing I love about Google
Guice is that it reduces the number of line of code. I know this
should not be the ultimate goal, but I find the "java bean" setters/
getters is a little bit heavy in some cases, especially when 90% they
are the same single line setter/getter logic. C# has a better way of
hanling this IMO.

Jeremy,

On Jul 2, 2:45 am, Willi Schönborn <[email protected]>
wrote:
> On 02/07/10 11:37, Maaartin-1 wrote:
>
>
>
> > IMHO, it's a sort-of bug or a missing feature. There's no nice solution
> > for the problem described. Quite often, a class knows suitable defaults
> > for missing ctor parameters and something like this should be supported.
> > Probably @Nullable is fine the way it works, but then there should be an
> > @Optional annotation on arguments allowing both a binding to null and a
> > missing binding.
>
> > You can achieve something like
>
> > @Inject
> > public void injectWebServiceProperties(
> > @Optional @Named("akui.webServiceURL") String webServiceUrl,
> > @Optional @Named("akui.webServiceUsername") String webServiceUsername,
> > @Optional @Named("akui.webServicePassword") String webServicePassword) {
> > ...
> > }
>
> Honestly, using 3 setters would be sooo much cleaner and easier to read.
>
>
>
> > only using field injection, which is obviously a bad thing. I've already
> > ran into this several times and I don't think it's so rare it should be
> > ignored.
>
> > On 10-07-02 10:31, [email protected] wrote:
>
> >> On Jul 1, 3:30 pm, Jeremy  Chone<[email protected]>  wrote:
>
> >>> Is this a wanted feature or a bug? Is there any way to avoid to have
> >>> one setter per property while keeping any of them optional?
>
> >> It's a feature. Although they're frequently confused, 'optional=true'
> >> and @Nullable mean quite different things.
>
> >> '@Inject(optional=true)' means that the injector should suppress any
> >> error from not being able to fulfill the dependencies of an injection.
> >> The injector will try its best to find bindings, even if that involves
> >> creating just-in-time bindings. But if any of the parameters to a
> >> method cannot be satisfied, the entire call is skipped.
>
> >> '@Nullable' means that the injector will not report an error if a null
> >> value is returned by the binding for an injection. The binding must
> >> still exist. The only time @Nullable is useful is when you implement a
> >> provider method (@Provides) or a provider class that may return null.

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to