3

I'm trying out PostSharp AOP and am surprised that OnMethodBoundaryAspect is not thread safe.

The same instance of the aspect is shared between method calls.

This makes its utility quite limited in number of use cases where it can be applied.

Any way to address this?

AVP06
  • 1,079
  • 1
  • 10
  • 16
  • Just to clarify I meant that the instance is shared between method calls of the same type, it seems that a new instance of the Aspect is created per method type but shared between calls of the same type. – AVP06 Aug 23 '12 at 01:50

1 Answers1

4

All OnEntry, OnExit and OnException methods receive a parameter of the type MethodExecutionArgs. This parameter has a property called MethodExecutionTag, and this one can be used for sharing information between these events.

http://doc.sharpcrafters.com/postsharp-2.1/Default.aspx##PostSharp-2.1.chm/html/P_PostSharp_Aspects_MethodExecutionArgs_MethodExecutionTag.htm

The third question on link http://www.sharpcrafters.com/blog/post/Stay-DRY-Webinar.aspx is similar as yours.

Fabio
  • 3,020
  • 4
  • 39
  • 62