打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Interception with Unity

Interception with Unity

2 out of 3 rated this helpful - Rate this topic

Unity interception enables you to effectively capture calls to objects and add additional functionality to the target object. Interception is useful when you want to modify the behavior for individual objects but not the entire class, very much as you would do when using the Decorator pattern. It provides a flexible approach for adding new behaviors to an object at run time.

This section contains the following topics that will help you to understand interception:

Unity provides both instance and type interception, and enables interception with either objects you resolve through the container, or by using the stand-alone API to explicitly invoke interception on a known instance.


Note:
Unity interception can be used without a Unity dependency injection (DI) container by using the stand-alone API through the static Intercept class. For more information see Using Interception in Applications.


The interception mechanism captures the call to an object at invocation time and provides the full implementation of the object. Unity uses the Interceptor class to specify the interception mechanism to be used, how interception happens, and the InterceptionBehavior class to describe what to do when an object is intercepted. Unity interception is designed to have its behaviors performed on the entire object and all of its methods. Interceptors play a role only at proxy (or derived type) creation time. Once the proxy, or derived type, is created, the interceptor has provided any required components for the intercepted object and incorporated them into the proxy's processing. The proxy can then complete its processing with no further input from the interceptor.


Note:
Proxy or type-creation time is the point of the largest performance hit.


Unity interception uses a single behaviors pipeline encompassing all of the behaviors for processing interception. The pipeline consists of an essentially fixed series of elements, the behaviors that you have set up, that perform pre- and/or post-processing logic on the object. If so dictated by the behavior element logic, each behavior element in the pipeline can end the invocations, and subsequent pipeline elements will not execute. The last executed element in the pipeline exits the pipeline and invokes the implementation of the intercepted object, thus enabling run-time processing. In post processing the process is reversed.

The following table describes the basic components of the Unity interception mechanism.

Interception Component

Description

Interceptor

Represents an interception mechanism. The interception mechanism actually intercepts the object call. There are two kinds of interceptors, type and instance. Unity provides a single type interceptor, VirtualMethodInterceptor, and two instance interceptors, Interface and TransparentProxy. For more information on type and instance interceptors see Unity Interception Techniques.

Interception behavior

Represents what to do when a method is intercepted. Behaviors always apply to every method on an intercepted type. Policy injection is just one such behavior.

Behaviors pipeline

A pipeline of behaviors that processing is routed to for interception.


Note:
Interception behaviors are a generalization of the default policy injection call handlers. The ICallHandler interface is very similar to the IInterceptionBehavior interface. A major difference is that the call handlers are passed to the method that they are called on.
The default policy injection call handlers target specific methods; but depending on the matching rules, they might target each and every method on an intercepted type, whereas Unity interception is designed to have its behaviors performed on the entire object and all of its methods.


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
初中初二八年级人教版英语上册全册教案下载
《计算机专业英语》Unit 8 Object-Oriented Programming
InfoQ: Microsoft Unity Dependency Injection A...
使用Unity实现 AOP
通过定义UnityContainer扩展变”Explicit Interception”为”Automatic Interception”
我心中的核心组件(可插拔的AOP)~第十三回 实现AOP的拦截组件Unity.Interception
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服