本文整理汇总了C#中IPolicyList.Set方法的典型用法代码示例。如果您正苦于以下问题:C# IPolicyList.Set方法的具体用法?C# IPolicyList.Set怎么用?C# IPolicyList.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPolicyList
的用法示例。
在下文中一共展示了IPolicyList.Set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddPolicies
/// <summary>
/// Add policies to the <paramref name="policies"/> to configure the
/// container to call this constructor with the appropriate parameter values.
/// </summary>
/// <param name="typeToCreate">Type to register.</param>
/// <param name="name">Name used to resolve the type object.</param>
/// <param name="policies">Policy list to add policies to.</param>
public override void AddPolicies(Type typeToCreate, string name, IPolicyList policies)
{
ConstructorInfo ctor = FindConstructor(typeToCreate);
policies.Set<IConstructorSelectorPolicy>(
new SpecifiedConstructorSelectorPolicy(ctor, parameterValues.ToArray()),
new NamedTypeBuildKey(typeToCreate, name));
}
示例2: AddPolicies
/// <summary>
/// Add policies to the <paramref name="policies"/> to configure the
/// container to call this constructor with the appropriate parameter values.
/// </summary>
/// <param name="serviceType">Interface registered, ignored in this implementation.</param>
/// <param name="implementationType">Type to register.</param>
/// <param name="name">Name used to resolve the type object.</param>
/// <param name="policies">Policy list to add policies to.</param>
public override void AddPolicies(Type serviceType, Type implementationType, string name, IPolicyList policies)
{
ConstructorInfo ctor = this.FindConstructor(implementationType);
policies.Set<IConstructorSelectorPolicy>(
new SpecifiedConstructorSelectorPolicy(ctor, this.parameterValues.ToArray()),
new NamedTypeBuildKey(implementationType, name));
}
示例3: AddPolicies
/// <summary>
/// Add policies to the <paramref name="policies"/> to configure the container to use the represented
/// <see cref="IInterceptor"/> for the supplied parameters.
/// </summary>
/// <param name="serviceType">Interface being registered.</param>
/// <param name="implementationType">Type to register.</param>
/// <param name="name">Name used to resolve the type object.</param>
/// <param name="policies">Policy list to add policies to.</param>
public override void AddPolicies(Type serviceType, Type implementationType, string name, IPolicyList policies)
{
var key = new NamedTypeBuildKey(implementationType, name);
if(IsInstanceInterceptor)
{
var policy = CreateInstanceInterceptionPolicy();
policies.Set<IInstanceInterceptionPolicy>(policy, key);
policies.Clear<ITypeInterceptionPolicy>(key);
}
else
{
var policy = CreateTypeInterceptionPolicy();
policies.Set<ITypeInterceptionPolicy>(policy, key);
policies.Clear<IInstanceInterceptionPolicy>(key);
}
}
示例4: AddPolicies
/// <summary>
/// Add policies to the <paramref name="policies"/> to configure the container with
/// an appropriate <see cref="IInstanceInterceptionPolicy"/>
/// </summary>
/// <param name="serviceType">Type of the interface being registered. This parameter is
/// ignored by this class.</param>
/// <param name="implementationType">Type to register.</param>
/// <param name="name">Name used to resolve the type object.</param>
/// <param name="policies">Policy list to add policies to.</param>
public override void AddPolicies(Type serviceType, Type implementationType, string name, IPolicyList policies)
{
var key = new NamedTypeBuildKey(implementationType);
policies.Set<IInstanceInterceptionPolicy>(new FixedInstanceInterceptionPolicy(Interceptor), key);
var piabInjectionMember = new InterceptionBehavior<PolicyInjectionBehavior>();
piabInjectionMember.AddPolicies(serviceType, implementationType, name, policies);
}
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:17,代码来源:InstanceInterceptionPolicySettingInjectionMember.cs
示例5: AddPolicies
/// <summary>
/// Add policies to the <paramref name="policies"/> to configure the
/// container to call this constructor with the appropriate parameter values.
/// </summary>
/// <param name="serviceType">Type of interface being registered. If no interface,
/// this will be null. This parameter is ignored in this implementation.</param>
/// <param name="implementationType">Type of concrete type being registered.</param>
/// <param name="name">Name used to resolve the type object.</param>
/// <param name="policies">Policy list to add policies to.</param>
public override void AddPolicies(Type serviceType, Type implementationType, string name, IPolicyList policies)
{
Guard.ArgumentNotNull(implementationType, "implementationType");
Guard.ArgumentNotNull(policies, "policies");
var policy = new FactoryDelegateBuildPlanPolicy(this.factoryFunc);
policies.Set<IBuildPlanPolicy>(policy,
new NamedTypeBuildKey(implementationType, name));
}
示例6: GetBehaviorsPolicy
/// <summary>
/// Get the list of behaviors for the current type so that it can be added to.
/// </summary>
/// <param name="policies">Policy list.</param>
/// <param name="implementationType">Implementation type to set behaviors for.</param>
/// <param name="name">Name type is registered under.</param>
/// <returns>An instance of <see cref="InterceptionBehaviorsPolicy"/>.</returns>
protected override InterceptionBehaviorsPolicy GetBehaviorsPolicy(IPolicyList policies, Type implementationType,
string name)
{
var policy = policies.GetNoDefault<IInterceptionBehaviorsPolicy>(implementationType, false);
if ((policy == null) || !(policy is InterceptionBehaviorsPolicy))
{
policy = new InterceptionBehaviorsPolicy();
policies.Set(policy, implementationType);
}
return (InterceptionBehaviorsPolicy) policy;
}
示例7: AddPolicies
public override void AddPolicies(Type serviceType, Type implementationType, string name, IPolicyList policies)
{
if (serviceType == null)
throw new ArgumentNullException(nameof(serviceType), "The service type cannot be null");
if (implementationType == null)
throw new ArgumentNullException(nameof(implementationType), "The implementation type cannot be null");
policies.Set(
typeof(ILazyProxyPolicy),
new LazyProxyPolicy(serviceType, implementationType),
new NamedTypeBuildKey(serviceType, name));
}
示例8: GetTracker
// Helper methods for adding and removing the tracker policy.
/// <summary>
/// Get an instance that implements <see cref="IDependencyResolverTrackerPolicy"/>,
/// either the current one in the policy set or creating a new one if it doesn't
/// exist.
/// </summary>
/// <param name="policies">Policy list to look up from.</param>
/// <param name="buildKey">Build key to track.</param>
/// <returns>The resolver tracker.</returns>
public static IDependencyResolverTrackerPolicy GetTracker(IPolicyList policies, object buildKey)
{
IDependencyResolverTrackerPolicy tracker =
policies.Get<IDependencyResolverTrackerPolicy>(buildKey);
if (tracker == null)
{
tracker = new DependencyResolverTrackerPolicy();
policies.Set<IDependencyResolverTrackerPolicy>(tracker, buildKey);
}
return tracker;
}
示例9: AddParameterResolvers
/// <summary>
/// Add dependency resolvers to the policy set.
/// </summary>
/// <param name="policies">PolicyList to add the resolvers to.</param>
/// <param name="parameterValues">Objects supplying the dependency resolvers.</param>
/// <param name="result">Result object to store the keys in.</param>
public static void AddParameterResolvers(IPolicyList policies,
IEnumerable<InjectionParameterValue> parameterValues,
SelectedMemberWithParameters result)
{
foreach(InjectionParameterValue parameterValue in parameterValues)
{
string key = Guid.NewGuid().ToString();
policies.Set<IDependencyResolverPolicy>(parameterValue.GetResolverPolicy(), key);
result.AddParameterKey(key);
}
}
示例10: AddPolicies
public override void AddPolicies(Type serviceType, Type implementationType, string name, IPolicyList policies)
{
var key = new NamedTypeBuildKey(implementationType, name);
var policy = policies.Get<InterceptorPolicy>(key);
if (policy == null)
{
policy = new InterceptorPolicy();
policies.Set(policy, key);
}
policy.AddInterceptor(this.interceptorContainer);
}
示例11: GetOrCreate
internal static InterceptionBehaviorsPolicy GetOrCreate(
IPolicyList policies,
Type typeToCreate,
string name)
{
NamedTypeBuildKey key = new NamedTypeBuildKey(typeToCreate, name);
IInterceptionBehaviorsPolicy policy =
policies.GetNoDefault<IInterceptionBehaviorsPolicy>(key, false);
if ((policy == null) || !(policy is InterceptionBehaviorsPolicy))
{
policy = new InterceptionBehaviorsPolicy();
policies.Set<IInterceptionBehaviorsPolicy>(policy, key);
}
return (InterceptionBehaviorsPolicy)policy;
}
示例12: GetOrCreate
internal static AdditionalInterfacesPolicy GetOrCreate(
IPolicyList policies,
Type typeToCreate,
string name)
{
NamedTypeBuildKey key = new NamedTypeBuildKey(typeToCreate, name);
IAdditionalInterfacesPolicy policy =
policies.GetNoDefault<IAdditionalInterfacesPolicy>(key, false);
if ((policy == null) || !(policy is AdditionalInterfacesPolicy))
{
policy = new AdditionalInterfacesPolicy();
policies.Set<IAdditionalInterfacesPolicy>(policy, key);
}
return (AdditionalInterfacesPolicy)policy;
}
示例13: AddPolicies
/// <summary>
/// Add policies to the <paramref name="policies"/> to configure the
/// container to call this constructor with the appropriate parameter values.
/// </summary>
/// <param name="serviceType">Type of interface being registered. If no interface,
/// this will be null.</param><param name="implementationType">Type of concrete type being registered.</param><param name="name">Name used to resolve the type object.</param><param name="policies">Policy list to add policies to.</param>
public override void AddPolicies(Type serviceType, Type implementationType, string name, IPolicyList policies)
{
if (implementationType == null) throw new ArgumentNullException("implementationType");
if(!implementationType.IsGenericType ||
implementationType.GetGenericTypeDefinition() != typeof(Validator<>))
{
throw new InvalidOperationException(Resources.IllegalUseOfInjectionValidationSource);
}
var key = new NamedTypeBuildKey(implementationType, name);
var policy = new ValidationSpecificationSourcePolicy(Source);
policies.Set<ValidationSpecificationSourcePolicy>(policy, key);
}
示例14: AddParameterResolvers
/// <summary>
/// Add dependency resolvers to the parameter set.
/// </summary>
/// <param name="typeToBuild">Type that's currently being built (used to resolve open generics).</param>
/// <param name="policies">PolicyList to add the resolvers to.</param>
/// <param name="parameterValues">Objects supplying the dependency resolvers.</param>
/// <param name="result">Result object to store the keys in.</param>
public static void AddParameterResolvers(Type typeToBuild,
IPolicyList policies,
IEnumerable<InjectionParameterValue> parameterValues,
SelectedMemberWithParameters result)
{
Microsoft.Practices.Unity.Utility.Guard.ArgumentNotNull(policies, "policies");
Microsoft.Practices.Unity.Utility.Guard.ArgumentNotNull(parameterValues, "parameterValues");
Microsoft.Practices.Unity.Utility.Guard.ArgumentNotNull(result, "result");
foreach(InjectionParameterValue parameterValue in parameterValues)
{
string key = Guid.NewGuid().ToString();
policies.Set<IDependencyResolverPolicy>(parameterValue.GetResolverPolicy(typeToBuild), key);
result.AddParameterKey(key);
}
}
示例15: SelectProperties
/// <summary>
/// Returns sequence of properties on the given type that
/// should be set as part of building that object.
/// </summary>
/// <param name="context">Current build context.</param>
/// <param name="resolverPolicyDestination">The <see cref='IPolicyList'/> to add any
/// generated resolver objects into.</param>
/// <returns>Sequence of <see cref="PropertyInfo"/> objects
/// that contain the properties to set.</returns>
public IEnumerable<SelectedProperty> SelectProperties(IBuilderContext context, IPolicyList resolverPolicyDestination)
{
Type typeToBuild = context.BuildKey.Type;
var currentTypeReflector = new ReflectionHelper(context.BuildKey.Type);
foreach(Pair<PropertyInfo, InjectionParameterValue> pair in propertiesAndValues)
{
PropertyInfo currentProperty = pair.First;
// Is this the property info on the open generic? If so, get the one
// for the current closed generic.
if (new ReflectionHelper(pair.First.DeclaringType).IsOpenGeneric)
{
currentProperty = currentTypeReflector.Type.GetProperty(currentProperty.Name);
}
string key = Guid.NewGuid().ToString();
resolverPolicyDestination.Set<IDependencyResolverPolicy>(pair.Second.GetResolverPolicy(typeToBuild), key);
yield return new SelectedProperty(currentProperty, key);
}
}