ArxOne / MrAdvice

.NET aspect weaver (build task under NuGet package)
MIT License
311 stars 45 forks source link

Advice on methods of child class #202

Open mmarjano opened 8 months ago

mmarjano commented 8 months ago

Hello,

I have my Advice as this:

public class MyProudAdvice : Attribute, IMethodAdvice
{
    public void Advise(MethodAdviceContext context)
    {
        // do things you want here
        context.Proceed(); // this calls the original method
                           // do other things here
    }
}

I have my Controller base class like this:

[MyProudAdvice]
public abstract class BaseController : Controller
{
}

My HomeController inherits BaseController.

The problem is, Advise method is triggered only for constructor of HomeController, not for the Index method. If I move MyProudAdvice attribute directly to HomeController, then Advise method is correctly triggered for all methods of HomeController. How can I achieve this using my base controller class? In PostSharp this was achieved using AttributeInheritance = PostSharp.Extensibility.MulticastInheritance.Multicast, but I see no similar option in documentation.

Thank you!

picrap commented 8 months ago

Hi,

If the advice attribute is inherit (which is the case by default), it should work. Otherwise, this seems to be a bug, I’ll take a look.