user9124444
user9124444

Reputation:

Subscribe to whatever method is being executed

In my app I'm creating an auditing package that obtains various information, one such type of information should provide different information regarding what method is executed (time it took to execute, method name, method class, assembly, etc).

I'm not looking to use an existing package or framework, but to create my own.

I can imagine that this is a complicated thing to do, but I'm looking for some pointers to get me started .

Upvotes: 1

Views: 64

Answers (1)

astef
astef

Reputation: 9488

One option you may be interested in is DI-level interception. Since container is responsible for your objects instantiation, sometimes it can be configured with proxy generators to enable call interception.

You can choose between Autofac, or Unity.

The most popular tasks to solve with this approach are cross-cutting concerns, like: logging, measurements, run-time application structure analysis. If you don't want to pollute your code base with repetitive diagnostic code, just delegate this task to an interceptor.

Similiar idea is AOP. I havn't seen popular AOP packages for a long time, and havn't used them, but it's worth to do a research on this topic too:

What is the best implementation for AOP in .Net?

DI Interception vs. AOP

Upvotes: 1

Related Questions