We are using a org.springframework.beans.factory.BeanFactoryAware
to run a chain of commands. All the services of the system use one service to do the audit logging. This audit logging service needs an unique identifier that is set in our implementation of the BeanFactoryAware
.
Right now this unique identifier is being passed down in each and every function call. One option is to have some type of context object that is pass around. It is preferiable NOT to do that because that would make the services less useable by other parts of the system that doesn't know about the BeanFactoryAware
system.
Is there some AOP way of implementing a cleaner solution? One where the audit logging can get the unique identifier without all the code between the BeanFactoryAware
and the audit code knowing the value?
Per the request, here is some code:
public class ChainRunner implements BeanFactoryAware
{
public int runChain(String chainName, Object initParameters, int msgLinkId) throws Exception {
OurContext ctx = createContext(initParameters);
ctx.setMsgLinkId(msgLinkId);
createChain(chainName).execute(ctx);
return retval;
}
}
public class AServiceImpl implements AService
{
private LoggingService logger;
public LoggingService getLogger() {
return logger;
}
public void setLogger(LoggingService logger) {
this.logger = logger;
}
public void aMethod(object params, int msgLinkId)
{
// lots of code snipped
logger().saveActionA( msgLinkId, otherParams);
}
}
public interface LoggingService
{
public void saveActionA(int msgLinkId, Object otherParams);
}
ChainRunner adds the msgLinkId to the chain's context. Each message will pull the the msgLinkId out of the context and pass it as an integer parameter down into a service, such as AServer.aMethod. Finally the service needs to log activity on the LoggerService, passing it parameters about what is being logged, where the first parameter is msgLinkId.
As it stands now, all the services are wired up via XML configuration:
<bean id="loggerService" class="com.nowhere.LoggingServiceImpl"/>
<bean id="aService" class="com.nowhere.AServiceImpl">
<property name="logger" ref="loggerService" />
</bean>
So the question is: Is it possible to use AOP to get msgLinkId to jump down to LoggingService without having to pass it through many layers of services?