Closed NewMySQL closed 2 years ago
Hello @NewMySQL ,
So lets start with question # 2 - AspectInjector is compile time framework. So unfortunately you cannot add any aspects at runtime. At least for now.
For the # 1 - unfortunately the same - overridden virtual methods do not inherit aspects. This feature though can be (samewhat) easily implemented.
As a temporal solution you can use Interface triggers, something like:
[Injection(typeof(Log))]
public interface IInheritAspects{
}
public class TestBase : Base
{
public override void Hello()
{
Console.WriteLine("Hello, Git Hub!");
}
}
public class Base : IInheritAspects
{
public virtual void Hello()
{
Console.WriteLine("Hello, World!");
}
}
the side effect is that then [Log]
will be injected into all and every methods of Base
and TestBase
. So you might need additional code to decide which method to log
Hello @NewMySQL ,
So lets start with question # 2 - AspectInjector is compile time framework. So unfortunately you cannot add any aspects at runtime. At least for now.
For the # 1 - unfortunately the same - overridden virtual methods do not inherit aspects. This feature though can be (samewhat) easily implemented.
As a temporal solution you can use Interface triggers, something like:
[Injection(typeof(Log))] public interface IInheritAspects{ } public class TestBase : Base { public override void Hello() { Console.WriteLine("Hello, Git Hub!"); } } public class Base : IInheritAspects { public virtual void Hello() { Console.WriteLine("Hello, World!"); } }
the side effect is that then
[Log]
will be injected into all and every methods ofBase
andTestBase
. So you might need additional code to decide which method to log
Many thanks for the answer. Temporary solution, it suits me more than ever)
1) Why inherited on attributes doesn't work? Code:
Wait after new TestBase().Hello():
Result after new TestBase().Hello():
2) How can I force an aspect to be added to certain methods at runtime?