15 Nov 2012 : Weld-OSGi in Action

You can find the slides of the presentation I did at Devoxx this year here

The code for the demo is available on my github account

https://github.com/mathieuancelin/demo-devoxx2012
comments »


19 Sep 2012 : How to use CDI in a Play 2 app

As you may know, I really love dependency injection and in Java EE project I tend to use it a lot. I’m also involved in the CDI 1.1 specification and the JBoss Weld project. You also know that I’m a big fan of Play! framework (both version 1 and 2) .

A few days ago, I saw a tweet from Guillaume Bort explaining how to integrate Spring in a Play 2 application (based on the work done from https://github.com/playframework/Play20/pull/365 ). As I already created a Play plugin to use CDI in a Play 1 application, I wrote a sample application showing how to use CDI in a Play 2 application, based on Guillaume’s sample app (thanks for the tip Guillaume). I’m not sure that it is really useful to use CDI in Play application, but here is how to do it anyway.

You can do the same on your app if your using Play 2.1 (you’ll have to build it from sources)

First, you need to add the Weld SE dependency. Here we use Weld SE because it’s really easy to bootstrap it programmatically. In the project/Build.scala file, add a dependency to weld-se

You also need to add an empty (or not) beans.xml file in your Play 2 app. so Weld will be able to boot. Just create a META-INF folder in the conf and create an empty beans.xml inside.

Then, you need to use dynamic controller dispatching in your application so Weld will be able to create the controller instances for you. To do that, just prefix your controller class name with the @ symbol in the routes file

When you do that, the controllers instances management will be delegated to the Global object of your application. Here is an implementation of the Global using Weld

Now, every class in your application is considered as a bean. If you want to exclude some classes, you need to write a CDI extension to veto bean types or you can use libraries like Seam Solder or DeltaSpike project to do the job. So we can write a basic service like the following

and use it in a Java controller

or even in a Scala controller

Note that the controller is a class and not an object. If your controller is an object you won’t be able to write something like the following in yoiur routes file

As you may have noticed, you can’t use web related scope with this implementation. To do so, you need to create a CDI extension that will provide a RequestScoped related context and handle requests from Global object to feed that context. I will try to write a blog post about it later.

You can find the sample application here

UPDATE : I updated my sample app to use CDI Events combined with Iteratees and SSE from both Scala and Java

https://gist.github.com/3755757

comments »


03 Jul 2012 : CDI par la pratique, le retour

The videos from my CDI presentation with Antoine Sabot-Durant at Devoxx France have been released.

(The Seam Social project has become Agorava project => http://agorava.org)

my slides are here :

and the Weld-OSGi demo video is available on youtube :


comments »