Details
-
New Feature
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
Patch
Description
I wonder if the DependencyManager API could be made a bit more fluent.
Technically it already uses the fluent builder pattern
but all the builder verbs still look a lot like traditional setters.
I know what I propose is mostly syntactic sugar but I think the result
looks more readable and crisp. See below for some ideas.
There is the concern about auto adding the component() to manager as it would acrivate the not fully configured component. We could perhaps overcome this by adding the component to a list of pending components first and then moving them to the active components after the init method.
The camel DSL solves this similarly.
This is from samples.dependonservice:
public void init(BundleContext context, DependencyManager manager)
throws Exception
Why not make it look like this:
public void init(BundleContext context, DependencyManager manager)
throws Exception
component() could create and add the component.
Or for configuration:
public void init(BundleContext context, DependencyManager manager)
throws Exception {
manager.add(createComponent()
.setImplementation(Task.class)
.add(createConfigurationDependency()
.setPid("config.pid")
// The following is optional and allows to display our
configuration from webconsole
.setHeading("Task Configuration")
.setDescription("Configuration for the Task Service")
.add(createPropertyMetaData()
.setCardinality(0)
.setType(String.class)
.setHeading("Task Interval")
.setDescription("Declare here the interval used to
trigger the Task")
.setDefaults(new String[]
)
.setId("interval"))));
}
could be:
public void init(BundleContext context, DependencyManager manager)
throws Exception