Tuesday, October 24, 2006

Allergic to annotations?

If you are like me, still allergic to annotations, but would like to inject stuff to your domain objects to keep them from becoming anemic, you cant rely on the spring docs (ATM) to give you a more simple explanation on using AspectJ for domain injection. The problem is magnified if your only use of aspects is for domain injection and nothing else (K.I.S.S. philosophy).

There is another way. You still need to download the usual AspectJ installer and the eclipse AJDT. Then create an aspectj project with a class like the code below.


package com.mobileindie.spring.utils;

import org.springframework.beans.factory.aspectj.AbstractBeanConfigurerAspect;
import org.springframework.beans.factory.wiring.ClassNameBeanWiringInfoResolver;

public aspect DomainObjectConfiguration extends AbstractBeanConfigurerAspect {

public DomainObjectConfiguration() {
setBeanWiringInfoResolver(new ClassNameBeanWiringInfoResolver());
}

// the creation of a new bean (any object in the domain model)
protected pointcut beanCreation(Object beanInstance) :
initialization(com.mobileindie.domains..new(..)) &&
this(beanInstance);

}


Take note of the initialization line, this is where you define which objects you would like to inject your dependencies whenever a new instance is called. This also assumes wire by prototype mode. But the beans are configured just like a normal bean in your spring application context xml.

devnox
- ano nga ba ang aspect kung meron kang aspect?

No comments: