On 04/08/2010 02:21 PM, Vincent Massol wrote:
Hi devs,
Since the JSR330 is now accepted as final and thus as a standard, I'd like to propose
that we modify our component annotations to use it.
+1
Rationale
========
The advantages of using it are:
* Be standard, ie:
** Our components will be able to be re-used by injectors other than ours (Guice for
example)
** Since IDEs will support JSR330 they'll be able to offer features for our code
(auto complete, graph, etc), for ex
http://blogs.jetbrains.com/idea/tag/dependency-injection/
Proposed Changes
===============
Note: JSR330 doesn't specify how components should be bound, hence the need to keep
xwiki-specific metadata for the bindings.
* @Component and @ComponentRole stay unchanged
Except that the package changes, right?
* Deprecate @Requirement, replaced by @Inject
* Use @Named or application-specific annotations (based on @Qualifier) instead of hints
specified in the @Requirement annotation
* Add new @Role(Class) to specify a dependency role in the case of collections (since
generics are not available using reflection in Java)
@Role will kind of break the "be standard, so supported by other
injectors" motivation. Are you sure there's no way for doing this? Maybe
we should have commented during the standardization process.
* Deprecate @InstantiationStrategy, replaced by
@Singleton. We don't need to introduce any other scope annotations for now.
* Note that the default scope in the JSR330 spec is "per lookup". Since our
default is singleton, we'll need to add @Singleton annotations everywhere we used to
not have anything.
This (@Singleton everywhere) is the biggest inconvenience, but we'll manage.
We also need to update the component tutorial.
Example before:
@Component("html")
public class HTMLMacro extends AbstractMacro<HTMLMacroParameters>
{
...
@Requirement
private HTMLCleaner htmlCleaner;
...
@Requirement("xhtmlmacro/1.0")
private PrintRendererFactory xhtmlRendererFactory;
...
@Requirement(role = Transformation.class)
private List<Transformation> transformations = new
ArrayList<Transformation>();
Same example after the change:
@Component("html")
public class HTMLMacro extends AbstractMacro<HTMLMacroParameters>
{
...
@Inject
private HTMLCleaner htmlCleaner;
...
@Inject
@Named("xhtmlmacro/1.0")
private PrintRendererFactory xhtmlRendererFactory;
...
@Inject
@Role(Transformation.class)
private List<Transformation> transformations = new
ArrayList<Transformation>();
Right?
--
Sergiu Dumitriu
http://purl.org/net/sergiu/