Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Params to Aspects?

Here is a simpler solution I like better than using Spring: put the aspect names into a resource bundle, which maps to argument list provided to the AbstractApect. The argument is constant and does not need to change, so this will work great.
 
Thanks
 
Bob


From: aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Adrian Colyer
Sent: Saturday, March 15, 2008 10:39 AM
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] Params to Aspects?

AspectJ doesn't provide any dependency injection features, but you can use AspectJ in conjunction with an IoC container that does.

See section 6.8.3 of the Spring Reference Guide for details on configuring aspects using Spring (http://static.springframework.org/spring/docs/2.5.x/reference/aop.html#aop-aj-configure).

Regards, Adrian.

On 15 Mar 2008, at 14:09, Buck, Robert wrote:

Hello,

I have a family of aspects that are all identical except for an
"internal" name I want to uniquely assign to each aspect instance.
Rather than write one aspect class for each, I'd like to reuse one class
for all. So what I would like to do is something like this:

<aspectj>
  <aspects>
    <concrete-aspect name="$com.verisign.aspectj.Hello$Aspect"
extends="com.verisign.aspectj.AbstractAspect">
      <pointcut name="scope" _expression_="execution(public *
*.hello(..))"/>
<param name="id" value="hello"/>  <<<<<<  THIS
    </concrete-aspect>
    <concrete-aspect
name="$com.verisign.aspectj.Goodbye$Aspect(&quot;goodbye&quot;)"
extends="com.verisign.aspectj.AbstractAspect">  <<<< OR THIS
      <pointcut name="scope" _expression_="execution(public *
*.goodbye(..))"/>
    </concrete-aspect>
  </aspects>
  <weaver>
    <include within="com.verisign.something.*"/>
  </weaver>
</aspectj>

In the above "hello world" example, the aspect would
"System.out.println(id);", or some such.

Is this sort of thing possible?

Alternatively, can one pass in a constructor argument to the named
concrete aspect from the XML definition?

Or, can one pass in arguments to the "scope" method that is generated?

Thanks in advance,

Bob
_______________________________________________
aspectj-users mailing list


Back to the top