Archive for February, 2009

Greg Young on Domain Driven Design

A Must See if you are interested in Domain Driven Design – InfoQ – Greg Young on DDD.
He also has a blog post about some of the topics he talks about in the interview – DDDD: Master-Detail Question

Being a DDD beginner myself, I found he has a wonderful ability to explain complex topics in very simple terms. Looking forward to reading the rest of his posts on DDD over the weekend.

Using Struts 2’s native dependency injection support

Since I knew that Struts 2 used Guice internally, I was curious if the native DI support in S2 could be used in a simple application. A little bit of digging and fiddling around showed what is possible.

struts.xml

...
 <constant name="myVal" value="9" />
 <bean name="myService" type="prac.MyService" class="prac.MyServiceImpl" />
...

MyServiceImpl.java

...
 @Inject("myVal")
 public void setMyVal(String myVal) {
 this.myVal = Integer.parseInt(myVal);
 }
...

MyAction.java

...
 @Inject("myService")
 public void setMyService(MyService myService) {
 this.myService = myService;
 }
...

This will create a single instance of MyService with myVal injected into it.
And on every invocation of MyAction, that MyService instance will be injected into it.
Sweet!

Of course, this is part of Struts internals, so these can change at any time. It is probably not a good idea to use it on a real world system.

Tags: ,