Finally, yesterday Adam Bien announced the afterburner community branch that he called topgun.

There you’ll find for the moment 3 enhancements that I contributed:

Named annotation support

This addition was the first Pull Request I submitted to afterburner.fx.

It is very simple and allows for injection of values which cannot be directly tied to a java attribute because of java naming conventions.

@Inject
@Named("user.dir")
private String workingDir;

It can be also necessary to use the @Named if you use program argument injection and that you have complex argument names.

Interface injection

This addition, tracked behind PR-34, allows the resolution of injection point that use an interface instead of a class type.

I provided it while thinking on how to plug external DI framework ; I thought first why not allow the already existing JRE service provider, ServiceLoader, to work with afterburner.fx.

Finally, if you have attributes declared using interface, whith this addition they will be resolved via the ServiceLoader by looking at your declared services in META-INF\services.

External DI framework support

Finally the third contribution, external DI support.

It allows you to use afterburner.fx with your preferred DI framework and not the internal afterburner.fx one.

Adam already thought about such kind of features by allowing to plug in afterburner an external function acting as instance provider for injection points & FXML controllers. This contribution extends this by enhancing a little bit this concept by defining a real InstanceProvider contract allowing to:

  • provide Object instances (that’s the first goal isn’t it ;-) )
  • bypass afterburner.fx internals for:
    • resolution of injection points
    • caching/scoping

Using afterburner.fx with your preferred DI framework is now possible and easy! Here is what you need to do in order to plug CDI (weld-se implementation). You have then the idea if you want to plug other DI framework.

Weld weld;
WeldContainer container;

weld = new Weld();
container = weld.initialize();

Injector.setInstanceSupplier(new Injector.InstanceProvider() {
    @Override
    public boolean isInjectionAware() {
        // CDI realizes injections
        return true;
    }

    @Override
    public boolean isScopeAware() {
        // CDI knows about scopes
        return true;
    }
    
    @Override
    public Object instanciate(Class<?> c) {
        return container.instance().select(c).get();
    }
});

Thank you Adam for providing this stuff to the community.

@AGFA healthcare we are still evaluating if we will finally use this or if we will go for a pure CDI solution, but if you use it with any external DI, please let me and Adam know about that.