Hi, I do need the property value to be injected, so the combination of a <provides> and <properties> section is a perfect solution for me. Thanks for clarifying!
Paul On 24 April 2011 14:56, Clement Escoffier <[email protected]> wrote: > Hi, > > Service properties can only be injected into fields or be 'static' (no > field). However, you can use a configuration property settings the service > property field: > <component name="MyServiceImpl" classname="MyServiceImpl"> > <provides specifications="MyService"> > <property name="my.prop" field="fooEnabledField" > /> > </provides> > <properties> > <!-- The constructor set the fooEnabledField field --> > <property name="fooEnabled" > constructor-parameter="0" > type="java.lang.Boolean" > mandatory="true"/> > </properties> > </component> > <instance component="MyServiceImpl"> > <property name="fooEnabled" value="true"/> > </instance> > <instance component="MyServiceImpl"> > <property name="fooEnabled" value="false"/> > </instance> > > If you don't need the injected value inside your code, just use a 'static' > service property: > > <component name="MyServiceImpl" classname="MyServiceImpl"> > <provides specifications="MyService"> > <property name="fooEnabled" type="java.lang.Boolean" > mandatory="true/>" > </provides> > </component> > > > Regards, > > Clement > > On 23.04.11 00:28, "Paul Neyens" <[email protected]> wrote: > >>Hi, >> >>I 'm currently discovering ipojo and I like it very much. >>One thing I am trying doesn't seem to work though: setting up a >>service with properties that should also be passed to the instance - >>preferably not through field injection. >> >>I tried some metadata that looks like this: >> >> <component name="MyServiceImpl" classname="MyServiceImpl"> >> <provides specifications="MyService"> >> <property name="fooEnabled" >> constructor-parameter="0" >> type="java.lang.Boolean" >> mandatory="true"/> >> </provides> >> </component> >> <instance component="MyServiceImpl"> >> <property name="fooEnabled" value="true"/> >> </instance> >> <instance component="MyServiceImpl"> >> <property name="fooEnabled" value="false"/> >> </instance> >> >>I also tried replacing the constructor-parameter line with >>method="setFooEnabled" (having a corresponding method, of course) >>but only field injection (field="fooEnabled") seems to work. >>In the other cases a service is registered but the property is never >>injected (through constructor or setter). >> >>Am I overlooking some mistake I made, is there another way to achieve >>this or is this a missing feature? >> >>Thanks, >> >>Paul >> >>--------------------------------------------------------------------- >>To unsubscribe, e-mail: [email protected] >>For additional commands, e-mail: [email protected] >> > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

