Details
-
Type: Improvement
-
Status: Closed
-
Priority: Trivial
-
Resolution: Cannot Reproduce
-
Affects Version/s: 1.0-alpha-2, 1.0-beta-1, 1.0-beta-2, (2)
1.0-beta-3, 1.0-beta-5 -
Fix Version/s: None
-
Component/s: PicoContainer (Java)
-
Labels:None
-
Number of attachments :
Description
Suppose I have CompA, CompB (depends on CompBConf).
CompA depends optionaly on CompB. If i don't register a CompBConf instance, i don't want CompB to be available, then a CompA less greedy constructor will be called and its member compB ref will be null.
To avoid registering a CompBConf I have to test explicitely if the method that creates this instance returns null or not.
It would be useful then to have an additional method on picocontainer to avoid every null checking :
registerComponentInstanceIfNotNull(Object obj)
Activity
Aslak Hellesøy
made changes -
Field | Original Value | New Value |
---|---|---|
Status | Unassigned [ 1 ] | Closed [ 6 ] |
Resolution | Cannot Reproduce [ 5 ] |
Is this right?
class A {
public A() {}
public A(B b) {}
}
class B {
public B(C c) {}
}
class C {
public C() {}
}
I don't quite understand what you want. Both of these should work:
a)
// A without B
pico.registerComponentImplementation(A.class);
A a = (A) pico.getComponentInstance(A.class);
b)
// A with B
pico.registerComponentImplementation(A.class);
pico.registerComponentImplementation(B.class);
pico.registerComponentImplementation(C.class);
A a = (A) pico.getComponentInstance(A.class);
Remember that we discourage registering instances (objects). The recommended way is to register classes and have pico instantiate them.