Calling decorated method in the same class doesn't call handler

Topics: Policy Injection Application Block
Nov 5, 2007 at 4:59 PM
Edited Nov 5, 2007 at 5:00 PM
I have code in my app that looks like this:

public override void Load()
{
// do some stuff

DoSomethingSpecial();
}

[HandleExceptionHandler]
public override void DoSomethingSpecial()
{
// do some stuff
}

[HandleExceptionHandler] is a custom attribute that I wrote to work with the Policy Injection Application Block. In this case, I am calling the method that is decorated with the attribute from inside the class, so the handler doesn't get called (that is, HandleExceptionHandler doesn't get called when I call DoSomethingSpecial() from Load()). Is there anything I can do to get around this?

Jon
Nov 6, 2007 at 7:04 AM
You'll need to have a policy-enabled reference to your own class in order for policies to be applied. Try something like this:
public override void Load()
{
    // do some stuff
    MyClassName wrappedThis = PolicyInjection.Wrap<MyClassName>(this);
    wrappedThis.DoSomethingSpecial();
}

Tom