开发者

InheritanceBasedAopConfigurer using runtime constructor arguments

I've got a (prototype) class owned by the Spring.NET context, created with an AutoProxy with runtime constructor arguments. It get's instantiated like this.

var context = ContextRegistry.GetContext();
var myClass = context.GetObject("myclass", new object[]{ myRuntimeConstructorArgument }) as MyClass;

This class has some inner logic going, where it catches an event that gets handled by a class method, like this:

// MyClass owned by Spring.NET context
public class MyClass {

  // InnerObject not owned by Spring context
  private InnerObject innerobject;

  // argument object not owned by Spring context
  public MyClass(ObjectNotOwnedBySpring myRuntimeConstructorArgument) {
     ...
     this.innerobject = new InnerObject();
     this.innerobject.SomeEvent += this.handleSomeEvent;
  }

  // I would like to intercept this event handler
  public virtual void handleMyEvent (object sender, EventArgs args)
  {
    // do stuff
  }
}

I'm trying to use AOP to remove an abstraction leak (caused by a bug in an external component), by intercepting the handleMyEvent method. Because Spring.Aop uses a proxy based approach to intercept method calls, inner method calls don't get intercepted. I get that part.

If I understand the documentation correctly, that's where the InheritanceBasedAopConfigurer comes into play, by using a 'true' inheritance based AOP mechanism. From the documentation:

Interception advice is added directly in the method body before invoking the base class method.

Exactly what I need!

Unfortunatly, I can't get the InheritanceBasedAopConfigurer get to play nicely with the runtime constructor arguments:

Spring.Objects.Factory.ObjectCreationException: Error creating object with name 'myclass' > defined in 'file [spring-aop-config.xml] line 36' : Could not resolve matching constructor.

Is runtime constructor arguments not supported by the InheritanceBasedAopConfigurer ? Or is this a wrong use case for the InheritanceBase开发者_StackOverflowdAopConfigurer ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜