f135ta / SimpleProxy

Simple Proxy implementation for Net Core using Castle Dynamic Proxy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Move Attribute to interface

phonglt7 opened this issue · comments

Hi, I've used your lib recently and it works great.
While using, I see that it's not a good practice to add the Attribute to the Class, I wonder if you can support then I can declare it in Interface?

Like this:

public interface MyInterface()
{
    [MyInterceptorAttribute]
    void MyMethod();
}

public class MyClass() : MyInterface
{
    void MyMethod()
    {
    }
}

Hello,
It’s my understanding that interfaces define contracts and are implemented by classes. The attributes applied to an interface wouldn’t be inherited or transferred in any way to the class. The way I have CastleProxy configured requires that the class is used with the attributes so that it can be wrapped and intercepted. I don’t see a way for that to work with the current setup. Do you have a proposal for how it might?

In my case, I want it to set in interface so any class implements it will be intercepted by the attribute, so the developers won't need to remember to put the attribute to their classes.
And I see your point, then I could try to set the attribute to the base class to take advantage of the inheritance.