Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime Aspect Loader feature #127

Open
nicewk opened this issue Apr 10, 2020 · 4 comments
Open

Runtime Aspect Loader feature #127

nicewk opened this issue Apr 10, 2020 · 4 comments

Comments

@nicewk
Copy link

nicewk commented Apr 10, 2020

Great job! It could be better if the Aspect attribute can add to the target automatically according to a config file.

@pamidur
Copy link
Owner

pamidur commented Apr 10, 2020

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)

@nicewk
Copy link
Author

nicewk commented Apr 11, 2020

Thanks @pamidur. That makes sense. I will try it.

@emisand
Copy link

emisand commented May 16, 2021

@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.

@pamidur
Copy link
Owner

pamidur commented May 20, 2021

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

@pamidur pamidur changed the title Add aspect attribute to target automatically Runtime Aspect Loader feature Oct 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants