Open blahlicus opened 2 years ago
Hi @blahlicus , sorry for delay. Indeed today Aspect Injector does not look for interface injections in the base classes. I believe this improvement is quite easy to implement.
Really interested in this feature. I accidentally opened a very similar request. Any updates on a possible implementation of this?
Hi @APEX-JOAQUIN-ROVIRA , I've recently moved countries, didn't have much time to look into this feature unfortunately.
But looking through your closed issue I was thinking if Injection.Inherited
might work for you
[Aspect(Scope.Global)]
[Injection(typeof(MyAspect), Inherited=true)]
public class MyAspect : Attribute
{
[Advice(Kind.Before, Targets = Target.Method)]
public void LogEnter() { Console.WriteLine($"Method call detected!"); }
}
[MyAspect]
public class A {
void Something() { } // Calls LogEnter()
}
public class B : A {
void Another() { } // Should log call too
}
@pamidur thank you for the quick reply and I hope you are doing well. I have tested the use of Inhertited = True
with the latest stable release (2.8.1
), and it does not seem to work as described. New functions such as B.Another()
do not call LogEnter()
.
Functions inherited from the base class A
do call LogEnter()
(i.e., B.Something()
calls LogEnter()
). If replaced with the override
or new
keywords, they do not - as one would expect.
Oh you're right, I totally forgot, this parameter only applies to Attributes so that Injection attributes can inherit aspects. It does not apply to target classes.
BTW you can still apply Aspect to whole assembly like this
[assembly: MyAspect()]
but I believe Injection.PropagationFilter will not be enough for you since it only filters member names and not class and namespace names.
I'll look at this feature again soon, stay tuned!
Thank you very much, I will actively look forward to any updates on the issue. 😃
I read about the assembly trick in the docs. However, I am weary of adding the advice to all methods of all classes unconditionally and checking if (instance is IExample) { ... }
as it could have a large performance impact, specially on highly modular code bases.
Oh you're right, I totally forgot, this parameter only applies to Attributes so that Injection attributes can inherit aspects. It does not apply to target classes.
BTW you can still apply Aspect to whole assembly like this
[assembly: MyAspect()]
but I believe Injection.PropagationFilter will not be enough for you since it only filters member names and not class and namespace names.
I'll look at this feature again soon, stay tuned!
Look forward to have this feature too. Will it arrive soon? Thanks in advance
Environment (please complete the following information):
Describe the question I don't think this is a bug per see, I think I'm just not using aspect-injector properly, please allow me to give the background info regardless:
In my program, there exists BaseClass, DerivedClass1, DerivedClass2, DerivedClass3, the derived classes have methods defined in them that are not overrides of the base class' methods. I implemented a simple interface injection with aspect-injector, I made it so that BaseClass implements my interface.
Instances of base class and dervied classes sucessfully have the AOP injection for the methods defined in the base class, but not for the methods newly defined in the derived classes, how can I make it so that the methods in the derived classes also get the code injection?
To Reproduce I have below sample code that I've ran that reproduces this issue: (ran in VS2022 preview with net6 MAUI)
To summarise, calling
method1()
from an instance ofc
triggers the injected code just fine, however, callingmethod3()
from the same instance does not trigger the injected code, I want to know how could I make it so callingmethod3()
will also trigger the injected code without having to addIHandleError
to classc
and classb
as well.