You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@click.apache.org by "Dennis M. J. Yerger" <de...@hotmail.com> on 2013/04/23 19:40:51 UTC

Click, Dependency Injection, and Annotations

I don't know if anyone has dealt with this yet, but dependency injection is a popular concept these days. Spring is the best example of such a framework. Some of Click's online examples are even based on Spring. However, Java EE has a new standard called Contexts and Dependency Injection (CDI). This specification has less dependence on XML than a typical Spring configuration. That means you can add your classes to your project and CDI will automatically detect them at startup. Detected classes can be filtered with qualifier annotations. 

Page interceptors can be automatically registered with Click by using standard CDI annotations such as ApplicationScoped. Consider the following example:

@RequestScoped
public class TestInterceptor implements PageInterceptor {...}

I propose adding an extension to Click to support CDI technology. I have already written working code to test this support, but I am not sure how to submit it. Any help is appreciated.

On a separate but related subject, Click makes little use of annotations in its configuration. The Bindable annotation makes request parameters easy to work with, but there are other possible uses for annotations. They can also be used for mapping a path to a page class. Consider the following example based on my test code:

@PagePaths("test.htm")
public class TestPage extends Page {
}

This is a very simple example. As you can see, the name of the annotation is PagePaths, implying that multiple paths can be mapped to the same class. Page headers are another place where annotations would be useful. Click should have a facility for detecting such annotations and including them in the overall configuration.