Re: [picocontainer-dev] Preferring Parameter names.....
Mauro Talevi <[email protected]>
| Newsgroups | gmane.comp.java.picocontainer.devel |
|---|---|
| Message-ID | <[email protected]> |
Paul Hammant wrote:
> Folks,
>
>>
>> You still have the problem that parameter names have no scope for the
>> component:
>>
>> class JDBCService {
>> JDBCService(URL endpoint, String username, String password);
>> }
>>
>> class SOAPService {
>> SOAPService(URL endpoint, String username, String password);
>> }
>>
>
> So Guice has 'binding annotations' for this. It is very verbose.
>
> See http://blog.decaresystems.ie/index.php/2007/06/14/juicy-code-with-google-guice-part-4/
> - search in page for 'binding annotations will help us'.
>
> I don't like it, but think we should do it too :-(
>
> I do like the simplicity and terseness of the parameter-name way we're
> currently doing, but Jorg highlights a shortcoming that the
> binding-annotations route does not have.
>
> *More customizable parameter name use*
>
> What if we also allow the following syntax :-
>
> pico.addConfig("jdbc_username", "fred");
> pico.addConfig("soap_username", "wilma");
> // etc
> pico.as(USE_NAMES("jdbc_")).addComponent(JDBCService.class);
> pico.as(USE_NAMES("soap_")).addComponent(SOAPService.class);
I think what this implies is that we're using namespace to differentiate.
But it reads funny - I would opt to rename USE_NAMES Characteristics to NAMESPACE (or somesuch).
pico.as(NAMESPACE("jdbc_")).addComponent(JDBCService.class)
reads much better IMO.
>
> That's about an hour's work on the current codebase.
>
> *An alternative using Parameter objects*
> *
> *
> pico.addComponent(JDBCService.class);
> *
> *
> *or ..*
> *
> *
> pico.with(new NamedParameter("jdbc_username"), new
> NamedParameter("jdbc_password")).addComponent(JDBCService.class);
>
> ... where with is also a varargs Parameter array thing and functions
> like 'as' ... on the next addComponent(..) only.
>
We can support both syntaxes, can't we?
Cheers
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email