开发者

.NET method invocation interception

开发者 https://www.devze.com 2023-01-13 22:47 出处:网络
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)开发者_StackOverflow中文版AO

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)开发者_StackOverflow中文版


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.


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.


for AOP could suggest this one PostSharp


You could use Castle DynamicProxy

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号