0

I have following code. Under order class I am calling DoSomething() explicitly inside ProcessOrder() and SubmitOrder() method.

But I want DoSomething to get called implicitly inside every public method of Order class whenever that method is called by external code. This is applicable to all the methods including the public methods that I will be adding to Order class in future.

public class Order
{
    private bool DoSomeThing()
    {
        // Do something and return result as bool
    }

    public void ProcessOrder()
    {
        DoSomeThing();
        // Process order logic
    }

    public void SubmitOrder()
    {
        DoSomeThing();
        // Process order logic
    }

}
  • Possible duplicate of [Implement method decorators in C#](https://stackoverflow.com/questions/15323009/implement-method-decorators-in-c-sharp) – Renat Jul 11 '19 at 07:34
  • I think you should use some IoC container with interceptors – Slava Utesinov Jul 11 '19 at 07:37
  • [This](https://stackoverflow.com/questions/27473012/how-can-i-write-interceptor-aop-with-castle-core-or-other-libraries-just-free) should get you started. Just build an interceptor and create a proxy for your Order class and pass that to consumers. – bartbje Jul 11 '19 at 13:39

0 Answers0