Share via


Specifying a Configuration Instance When Creating and Wrapping Objects

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.

The static Create and Wrap methods of the PolicyInjection class also accept an optional parameter containing a reference to a class that implements the IConfigurationSource interface. This interface is part of the core Enterprise Library configuration system, and it allows developers to create custom instances of the configuration data to pass to an application block when creating instances of classes in an application block.

To use a custom configuration source when creating an instance of a target class that inherits from MarshalByRefObject, specify the configuration source reference as the first parameter when calling the Create method, as shown in the following code.

TargetClass theTarget = PolicyInjection.Create<TargetClass>(configSource, parameter1, ...);
'Usage
Dim theTarget As TargetClass = PolicyInjection.Create(Of TargetClass)(configSource, parameter1, ...)

Likewise, to use a custom configuration source when creating an instance of a target object that implements a known interface, specify the configuration source reference as the first parameter when calling the Create method.

ITargetInterface theTarget 
  = PolicyInjection.Create<TargetClass, ITargetInterface>(configSource, parameter1, ...);
'Usage
Dim theTarget As ITargetInterface _
  = PolicyInjection.Create(Of TargetClass, ITargetInterface)(configSource, parameter1, ...)

To use a custom configuration source when wrapping an existing instance of a target object, specify the configuration source reference as the first parameter when calling the Wrap method with the target interface type.

ITargetInterface theTarget = PolicyInjection.Wrap<ITargetInterface>(configSource, existingObject);
'Usage
Dim theTarget As ITargetInterface = PolicyInjection.Wrap(Of ITargetInterface)(configSource, existingObject)

Likewise, if the existing target object inherits form MarshalByRefObject, specify the configuration source reference as the first parameter when calling the Wrap method with the target object type.

TargetObject theTarget = PolicyInjection.Wrap<TargetObjectType>(configSource, existingObject);
'Usage
Dim theTarget As TargetObject = PolicyInjection.Wrap(Of TargetObjectType)(configSource, existingObject)