cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carsten Ziegeler <cziege...@apache.org>
Subject Re: [RT] Simplifying component handling
Date Sat, 31 Dec 2005 14:54:12 GMT
Joerg Heinicke wrote:
> On 30.12.2005 19:09, Carsten Ziegeler wrote:
> 
> 
>>class MyComponent implements SOMETHING, ThreadSafe, Disposable,
>>Serviceable {
>>protected ClassA compA;
>>protected ClassB compB;
>>protected ServiceManager m;
>>
>>public void service(ServiceManager m) {
>>  this.m = m;
>>  compA = (ClassA)m.lookup(ClassA.ROLE);
>>  compB = (ClassB)m.lookup(ClassB.ROLE);
>>}
>>public void dispose() {
>>  if ( m != null ) {
>>    m.release(compA);
>>    m.release(compB);
>>  }
>>}
>>
>>Way too much code me thinks. So what about:
>>
>>class MyComponent implements SOMETHING, ThreadSafe {
>>  protected final ClassA compA;
>>  protected final ClassB compB;
>>
>>  public MyComponent(ClassA a, ClassB b) {
>>    compA = a;
>>    compB = b;
>>  }
>>}
>>
>>We could simply add constructor injection: if the implementation does
>>not provide a default constructor, the available constructor is called
>>using reflection and the components are injected on construction of the
>>object - no need to configure something in any xml configuration file.
>>Implementing this is easy - I did this already years ago for Fortress.
> 
> 
> What's the contract for the auto-wiring? Just assuming ClassA and ClassB 
> have public static fields called ROLE? Sounds somewhat "strange".
> 
No, the contract would be to search for a component which is registered
using the ClassA as the role name. Actually ClassA and ClassB are two
interfaces.

Carsten
-- 
Carsten Ziegeler - Open Source Group, S&N AG
http://www.s-und-n.de
http://www.osoco.org/weblogs/rael/

Mime
View raw message