I need to intercept method invocations... please suggest a ready-made solution. It's necessary to block access to some methods (so calling them will generate an exception)
Aspect Orientated Programming facilitates this sort of task. There are many framworks to use, I've used Spring.Net which is pretty good.
Using Interception with Unity.
There's your ready-made solution, part of the Microsoft Enterprise Library.
You could use Castle DynamicProxy
Or even the built-in RealProxy
class (requires that your class inherits MarshalByRefObject
)
AOP offers the functionality you a looking for. For a full AOP solution you can use PostSharp.
Since you are just searching for a way to intercept method calls, you just need a subset of AOP. So any IoC container which offers interface interception is also suitable. To my knowledge Spring.NET, Unity and Castle Windsor offers interface interception.
Edit: If you need interception really fast and have an existing code base, I suggest to use PostSharp. In order to use some IoC container you maybe need to modify a lot of code. If you have a new project consider IoC. Designing an application using IoC has a lot of positive effects.