Puresharper / Puresharp

Puresharp is a Framework that provides the essential APIs (AOP, IOC, etc...) to productively build high quality (.NET 4.5.2+ & .NET Core 2.1+) applications through reliability, scalability and performance without no compromise
MIT License
143 stars 17 forks source link

Add method arguments to IAdvice.Begin #14

Open VanKrock opened 5 years ago

VanKrock commented 5 years ago

IAdvice.Begin doesn't have method arguments

Arguments needed for templates, such as

[Log("My method: {value}")]
void MyMethod(string value);

IAdvice.Begin can be

void Begin(object[] args);
Puresharper commented 5 years ago

Hi,

You have to implements method Argument(T value) and store value in a field. exemple

public Advice1 : IAdvice
{
    private readonly List<object> arguments;

    public void Argument<T>(ref T value)
    {
        this.arguments.Add(value);
    }

    public void Begin()
    {
        this.arguments... //here list of arguments?
    }
    ...
}
VanKrock commented 5 years ago

It's will work if I call my method twice?

Puresharper commented 5 years ago

Yes, it depends how you create your "aspect/advisor"

public class Logging : Aspect
{
    override public IEnumerable<Advisor> Manage(MethodBase method)
    {
        yield return Advice
            .For(method)
            .Around(() => new Log(method));
    }
}

here the delegate to create 'Log Advice' is called each time you call your method. This is what I recommend to manage method call contextual datas. In this case you can even specialize an advice depending on target method.