views:

81

answers:

5

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)

+1  A: 

for AOP could suggest this one PostSharp

Arseny
+2  A: 

Aspect Orientated Programming facilitates this sort of task. There are many framworks to use, I've used Spring.Net which is pretty good.

JonoW
http://www.springframework.net/
VirtualBlackFox
+2  A: 

Using Interception with Unity.

There's your ready-made solution, part of the Microsoft Enterprise Library.

Slavo
+1  A: 

You could use Castle DynamicProxy

Or even the built-in RealProxy class (requires that your class inherits MarshalByRefObject)

Thomas Levesque
+4  A: 

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.

Theo Lenndorff