This project is read-only.

Mixins & PerThis lifecycle

Jan 15, 2013 at 7:07 AM
Edited Jan 15, 2013 at 7:13 AM


I'm attempting to use Mixins with a PerThis lifecycle ... it doesn't work.  As far as I can tell, it isn't actually implemented, so you probably already know it doesn't work.

Initially I was getting a null pointer exception.  I think this is an error in MixinsImplementationBinding.cs.  Around line 38 you have:

var aspect =
    AspectRuntime.GetAspect(new MethodJointPoint(ctor, instance, args,
        delegate{throw new NotImplementedException();}));

With PerThis lifecycle, the aspect is not found,so you change the selector to throw an exception.  You should have assigned to "_selector" instead of "selector" in the lines below.

if(aspect == null)
   selector = _ => { throw new NotImplementedException("SheepAspect Mixin has no implementation"); };


From what I can tell after reading far too much disassembled IL is in MixinsImplementationBinding, you manufacturer a joinpoint based on the constructor of the object receiving the mixin.  This transient MethodJoinPoint doesn't implement IMayHaveAspect, so the PerThisAspectLifecycle can't find the aspect instance associated with the target object.

What I can't tell is how to fix any of this.  It seems like there should be an actual MixinJoinPoint that the PerThisAspectLifecycle can use to attach the IMayHaveAspect implementation.  But IMayHaveAspect seems to be attached to the aspect class, not the JoinPoint.

So, is there a relatively simple way to make Mixins work with PerThis?


Jan 16, 2013 at 12:44 AM

Hi dkantowitz,

That code flow will only get reached in scenario when you call a mixed-in interface methods, but no instance of your aspect is currently available (usually because it's outside of the aspect's lifecycle, e.g. when using [AspectPerCFlow] or [AspectPerThis] and you try to access the mixed interface from outside the covered CFlow or This isntances). In that scenario, the expected behavior is for the system to throw a NotImplementedException when SheepAspect can't find the implementation of the mixed-in interface methods. But you're right, the code had some issue there which caused a NullReferenceException instead of a NotImplementedException, and has been fixed in v0.3.0.7.

Thanks for reporting the issue.

I'll send you a separate message in regards to the problem you're having with AspectPerThis in your EditableObject aspect implementation.

Jan 16, 2013 at 5:54 AM

That makes sense. Thanks for the explanation.