Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

How to declare a component type

Section
Column
width50%
Code Block
xml
xml
titleXML

<component
    classname="my.Implementation"
    name="my-type"
>
</component>
column
width50%
Code Block
java
java
titleAnnotations

@Component(name="my-type")
public class Implementation {
  // ...
}
Center

How to declare instances

...

100%
Code Block
xml
xml

<instance component="my-type"/>
<instance component="my.Implementation"/>
<instance component="my-type" name="my-instance"/>
<instance component="my-type" name="my-instance">
    <property name="property1" value="value1"/>
</instance>
</component>

Attribute name

Required

Default value

 

component

yes

 

specifies the component type (either by using the name or the class name)

name

no

generated

specifies the instance name.

Center

  • Instances can contains a configuration given under the key-value form.

...

How to provide a service

Code Block
xml
xml
titleXML

<component classname="my.service.implementation" name="my-service-impl">
   <provides/>
</component>
<instance name="my-service-impl"/>
Code Block
java
java
titleAnnotations

@Component
@Provides
public class Implementation implements FooService {
   ...
}
  • Only instances provides really services, so don't forget to declare an instance.
  • Published service interfaces must be implemented by your component implementation
    Center

Publishing service properties

Code Block
xml
xml
titleXML

<component classname="my.service.implementation" name="my-service-impl">
  <provides>
	<property name="foo" field="m_foo" />
	<property name="bar" field="m_bar" mandatory="true" />
	<property name="baz" type="java.lang.String" /> <!-- Static property (do not change at runtime) -->
  </provides>
</component>
<instance name="my-service-impl"> <!-- The configuration has to inject value in unvalued mandatory properties -->
  <property name="bar" value="5"/>
  <property name="baz" value="my string"/>
<instance/>
Code Block
java
java
titleAnnotations

@Component
@Provides(specifications= {FooService.class, BarService.class})
public class ProvidesProperties implements FooService, BarService {
    
    @ServiceProperty(name = "foo")
    public int m_foo = 0;
    
    @ServiceProperty(name="bar", mandatory=true)
    public int m_bar;
    
// ...
}
Center