pamidur / aspect-injector

AOP framework for .NET (c#, vb, etc)
Apache License 2.0
745 stars 112 forks source link

Enhancement: Make it possible to bind all arguments to a complex object #147

Closed StefH closed 2 years ago

StefH commented 3 years ago

Currently you have to specify each Argument separately:

[Advice(Kind.Around, Targets = Target.Public | Target.Method)]
        public object? Handle(
            [Argument(Source.Instance)] object instance,
            [Argument(Source.Target)] Func<object[], object> target,
            [Argument(Source.Arguments)] object[] args,
            [Argument(Source.Name)] string name,
            [Argument(Source.ReturnType)] Type returnType,
            [Argument(Source.Triggers)] Attribute[] triggers)
        {

It would be very useful to be able to just do this:

[Advice(Kind.Around, Targets = Target.Public | Target.Method)]
        public object? Handle([Argument(Source.Complete)] AspectArguments arguments)
        {
pamidur commented 3 years ago

Hi @StefH , this is not a hard thing to implement, and was chosen not to because of performance reasons - providing such object will require to calculate all the properties even if those aren't used.

Could you please provide your reasoning for this enhancement so we could take a look at it from another point of view?

StefH commented 3 years ago

This is related to https://github.com/pamidur/aspect-injector/issues/145

When I want to build a generic aspect which can handle many scenarios, I probably need all Argument-sources because I want to expose as much as information as possible to the OnXXX methods to the caller.

(I'll create a PR to indicate what I've in mind....)

pamidur commented 2 years ago

I guess this should cover it https://github.com/pamidur/aspect-injector/pull/148 Feel free to reopen if needed