Export (0) Print
Expand All

Interception Configuration Schema Elements

When configuring files for interception, the following elements may appear as children of a <register> element. For more information see The register Element. These elements are used to describe the <interceptors> and <policies> elements, their child elements, and their attributes in more detail:

For more information about interception, and selecting the objects and their members to add a handler pipeline, see Using Interception and Policy Injection.

The interceptor element specifies a type that should be intercepted and provides the type of interceptor to use.

The <interceptor> element is a valid child of the <register> element.

The following table lists the attributes for the interceptor element.

Attribute

Description

name

The name to use when registering this interceptor. This attribute is required only when there are two or more entries for the same interceptor type.

type

The type of the interceptor. This attribute is required.

isDefaultForType

Default is false. If true, then this interceptor will be used for all registrations for this type, ignoring the name that the registration is under. This flag is useful if you are registering many implementations of the same interface with different names, and want all of them intercepted. Setting this to "true" lets you define interception once instead of in every registration. This attribute is optional.

There are no valid child elements for the <interceptor> element.

This <interceptionBehavior> element specifies which interception behaviors will be executed when the intercepted object is called. This element may appear multiple times, with each instance adding a separate behavior interface.

The <interceptionBehavior> element is a valid child of the <register> Element.

The following table lists the attributes for the interceptionBehavior element.

Attribute

Description

name

The name, if provided, used to resolve the interceptor type. Behaviors are resolved out of the container. This attribute is optional.

type

The Type of behavior to create. This attribute is required.

isDefaultForType

Default is false. If true, then this behavior will be applied for all registrations for this type, ignoring the name that the registration is under. This flag is useful if you are registering many implementations of the same interface with different names, and want all of them intercepted. Setting this to true lets you define the behavior once instead of in every registration. This attribute is optional.

There are no valid child elements for the <interceptionBehavior> element.

This <addInterface> element lets you implement additional interfaces. It is possible for the interception system to add extra interfaces to the proxy classes that are created. These are interfaces above and beyond the interfaces that are implemented by the intercepted types. These interfaces must be implemented by an appropriate interception behavior. In most cases, the behavior itself will indicate when it adds an interface. There are occasions, such as for a mock object framework, when the behavior itself could implement any interface or a large set of interfaces. If you are using such a behavior, you need to explicitly indicate which interfaces to add. This element enables you to do that. This element may appear multiple times with each appearance adding an individual interface.

The <addInterface> element is a valid child of the <register> Element.

The following table lists the attributes for the addInterface element.

Attribute

Description

type

The interface to add. This attribute is required.

There are no valid child elements for the <addInterface> element.

<register type="MyViewModel">
  <interceptor type="VirtualMethodInterceptor" />
  <interceptionBehavior type="SpecialSupportBehavior" />
 <addInterface type="ISupportInterface1" />
</register>

This <interception> element is used to group together a set of policy injection policy definitions.

The <interception> element is a valid child of the <container> Element.

The <interception> element has no valid Attributes.

The <interception> element has one valid child element, the <policy> element.


Each policy element is used to define a policy injection policy and specifies the complete configuration for a single policy.

The <policy> element is a valid child of the <interception> element.

The following table lists the attributes for the policy element.

Attribute

Description

name

The name to use when registering this policy. All policies must have unique names. This attribute is required.

The policy element has two valid child elements, the <matchingRule> Element and the <callHandler> Element, that specify details of the policy.

Each matchingRule element defines a matching rule object that will be used when determining if its containing policy will be applied in policy injection. All of the matching rules within a matchingRules element must evaluate to True for a policy to apply to a specific type or member of a type.

The <matchingRule> element can be used in multiple ways to define a matching rule object directly in the policy or to reference one that has been defined elsewhere in the container. See Configuring Policy Injection Policies for more information.

The <matchingRule> element is a valid child of the <policy> element.

The following table describes the attributes of the matchingRule element.

Attribute

Description

name

The name by which code in Unity and the configuration tools will refer to this matching rule. This attribute is required.

type

The type of object that will be created and registered with the container. If omitted, the container will be used to resolve the matching rule. The container will search for a mapping of IMatchingRule with the name supplied in the name attribute

This attribute is not required if the types are registered elsewhere within the configuration, and the name attribute matches one of these named registrations.


Matching rules are only used to determine which policies apply for each interceptable method. They are not used at run time.

The matchingRule element has the valid child element, the <lifetime>Element, and any other elements derived from InjectionMemberElement.

Each callHandler element defines a call handler object that will be used when determining if its containing policy will be applied in policy injection. It provides the details of a single call handler. The <callHandler > element can be used in multiple ways to define a call handler object directly in the policy or to reference one that has been defined elsewhere in the container. See Configuring Policy Injection Policies for more information.

The <callHandler> element is a valid child of the <policy> element.

The following table describes the attributes of the callHandler element.

Attribute

Description

name

The name of the call handler and the name by which code in Unity and the configuration tools will refer to this call handler. The name must be unique within the policy. This attribute is required.

type

The type of the call handler. If provided, this is the type of object that will be created and registered with the container. If omitted, the container will be used to resolve the matching rule, looking for a mapping of ICallHandler with the name supplied in the name attribute.

This attribute is not required if the types are registered elsewhere within the configuration, and the name attribute matches one of these named registrations.

The matchingRule element has the valid child element, the <lifetime> element, and any other elements derived from InjectionMemberElement.

The <interceptors> element is part of the legacy support for Unity 1.x configuration files. It is recommended that for new development you define interception directly in the <register> Element by using the <interception> element and the rest of the interception elements. See Legacy Interception Configuration for more information.

The <interceptors> element is a valid child of the <container> element.

There are no the attributes of the interceptors element.

The <interceptors> element has one valid child element, the <interceptor> element>.

This <interceptor> element, when placed within the <interceptors> element, is used to enable interception on a type that is otherwise registered elsewhere in the configuration file.


Ff660900.note(en-us,PandP.20).gifNote:
There are two <interceptor> elements. They are actually two different elements (different C# classes) that have the same name in the XML. The meaning changes based on context (where they are in the XML file. They can appear in the <register> element or in the <interceptors> element and are defined accordingly.


It is recommended that for new development you define interception directly in the <register> Element by using the <interceptor> Element and the rest of the interception elements. See Legacy Interception Configuration for more information about the <interceptors> element.

The following table lists the attributes for the interceptor element.

Attribute

Description

type

The type of the interceptor to create. This attribute is required.

value

If a type converter is used to create the interceptor, this value is passed to the type converter. If left out, the type converter will receive null. This attribute is optional.

typeConverter

The type converter to use to create the interceptor. If omitted, the interceptor is created with Activator.CreateInstance.

There are two valid child elements for the <interceptor> element, the <default> element and the <key> element.


The <default> element specifies which types to apply the containing interceptor to. The interceptor will be applied every time this type is resolved from the container, regardless of which name is used to resolve it.

It is recommended that for new development you define interception directly in the <register> Element by using the <interceptor> element and the rest of the interception elements

The <default> element is a valid child of the interceptors <interceptor> element. . See Legacy Interception Configuration for more information about the <interceptors> element and its child elements.

The following table lists the attributes for the key element.

Attribute

Description

type

Type to apply the interceptor to. This attribute is required.

There are no valid child elements for the <default> element.

The <key> element is used to specify which types to apply the containing interceptor to. The interceptor will be applied only to the type/name pair specified in the attributes of this element. The name and type attributes of the <key>element specify the type of the object that should be intercepted when resolved.

It is recommended that for new development you define interception directly in the <register> Element by using the <interceptor> element and the rest of the interception elements.

The <key> element is a valid child of the interceptors <interceptor> element. . See Legacy Interception Configuration for more information about the <interceptors> element and its child elements.

The following table lists the valid attributes for the <key>element.

Attribute

Description

name

The name of the registration to apply interception to. If omitted, the interceptor is applied to the default registration. The name attribute is only required where you configure more than one key for the same type. This attribute is optional.

type

The type to apply the interceptor to. This attribute is required.

There are no valid child elements for the <key> element.


Show:
© 2014 Microsoft