Open nicewk opened 4 years ago
Hi! Thanks! I'm actually working on something like this. But the idea is not the config file but kinda fluent loader. So you'll be able to do something like:
var assembly = AspectLoader.Load(filename, loader => {
loader.Inject(typeof(LogAspect)).IntoMethod(m => m.Attributes == MethodAttributes.Public);
});
This might be useful if don't own target assembly. E.g. test loader or custom application loader/partcher.
If you instead own target assembly you can use Propagate feature like this:
[Aspect(Scope.Global)]
[Injection(typeof(LogAspect), Propagation = PropagateTo.Types | PropagateTo.Methods, PropagationFilter = "^MyMethod")]
public class LogAspect : Attribute
{
[Advice(Kind.Before, Targets = Target.Method | Target.Public)]
public void Log([Argument(Source.Name)] string method)
{
Console.WriteLine($"Entering {method}");
}
}
And then apply it to assembly
[assembly:LogAspect]
Let me know if it works for you, and how would you like it work otherwise. Your usage scenarios would be plus)
Thanks @pamidur. That makes sense. I will try it.
@pamidur Is the AspectLoader or Propagation features already implemented? This is the kind of feature I need to apply aspects to classes that implement an interface from a framework I'm working on. I would need to implement some reflection filters to check if a method is within a class with some specific interfaces or attributes in order to apply the aspect.
Hi @emisand , unfortunately AspectLoader is not ready (not even close to ready as there is some technical difficulties) There is another feature though that might be of some interest to you - Interface triggers which allows you to have some injection based on implemented interface - see here https://github.com/pamidur/aspect-injector/releases/tag/2.5.0
Great job! It could be better if the Aspect attribute can add to the target automatically according to a config file.