Hi,

I have two questions. To start with a simple one - is there a way to let iPOJO 
create default (empty) component instances on demand when requested by 
@Requested annotation? I only found a possibility of explicit instantiation via 
@Instantiate annotation explicitly but the on-demand one would be nice.

The second question might be linked to the previous one. I'd like to have a 
component (logger) that gets parametrized by requesting components. I found 
that a way to get it working might be using strategies like this:

@Component
@Provides(strategy="LoggerComponentStrategy")
class LoggerComponent implements LoggerComponentInterface {
 ...
}

public class LoggerComponentStrategy extends ConfigurableCreationStrategy 
implements ServiceObjectFactory {
    @Override
    protected ServiceObjectFactory getServiceFactory(final InstanceManager 
manager) {
        return this;
    }

    @Override
    public Object getService(final ComponentInstance instance) {
        final String name = 
instance.getInstanceDescription().getComponentDescription().getName();
        return safelyCreateLogger(name);
    }
  ...
}

@Component
@Instantiate
class B {
    @Requires LoggerComponentInterface l;
}

B gets only instantiated when the LoggerComponent class is annotated with 
@Instantiate annotation, ie. there already exists a Logger instance in iPOJO 
manager. That empty instance however is not used (and never will): the obtained 
instance of Logger injected into B must be parametrized with "B" name. Is there 
any way to have B initialize with the correct logger without the necessity of 
that useless empty Logger instance?

Thanks,

--Hynek

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to