本文整理汇总了C#中IPolicyList类的典型用法代码示例。如果您正苦于以下问题:C# IPolicyList类的具体用法?C# IPolicyList怎么用?C# IPolicyList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IPolicyList类属于命名空间,在下文中一共展示了IPolicyList类的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: ContainerRegistration
internal ContainerRegistration(Type registeredType, string name, IPolicyList policies)
{
this.buildKey = new NamedTypeBuildKey(registeredType, name);
MappedToType = GetMappedType(policies);
LifetimeManagerType = GetLifetimeManagerType(policies);
LifetimeManager = GetLifetimeManager(policies);
}
示例3: SelectMethods
/// <summary>
/// Return the sequence of methods to call while building the target 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 methods to call.</returns>
public IEnumerable<SelectedMethod> SelectMethods(IBuilderContext context, IPolicyList resolverPolicyDestination)
{
foreach (Pair<MethodInfo, IEnumerable<InjectionParameterValue>> method in methods)
{
Type typeToBuild = context.BuildKey.Type;
SelectedMethod selectedMethod;
var typeReflector = new ReflectionHelper(method.First.DeclaringType);
var methodReflector = new MethodReflectionHelper(method.First);
if (!methodReflector.MethodHasOpenGenericParameters && !typeReflector.IsOpenGeneric)
{
selectedMethod = new SelectedMethod(method.First);
}
else
{
Type[] closedMethodParameterTypes =
methodReflector.GetClosedParameterTypes(typeToBuild.GetGenericArguments());
selectedMethod = new SelectedMethod(
typeToBuild.GetMethod(method.First.Name, closedMethodParameterTypes));
}
SpecifiedMemberSelectorHelper.AddParameterResolvers(
typeToBuild,
resolverPolicyDestination,
method.Second,
selectedMethod);
yield return selectedMethod;
}
}
示例4: SelectProperties
public IEnumerable<SelectedProperty> SelectProperties(IBuilderContext context, IPolicyList resolverPolicyDestination)
{
var t = context.BuildKey.Type;
var propertyNames = new HashSet<string>();
foreach (SelectedProperty prop in specifiedPropertiesPolicy.SelectProperties(context,resolverPolicyDestination))
{
if (!propertyNames.Contains(prop.Property.Name))
{
propertyNames.Add(prop.Property.Name);
yield return prop;
}
}
foreach (SelectedProperty prop in defaultProlicy.SelectProperties(context,resolverPolicyDestination))
{
if (!propertyNames.Contains(prop.Property.Name))
{
yield return prop;
}
}
foreach (PropertyInfo prop in t.GetProperties(BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.Instance))
{
if (prop.GetIndexParameters().Length == 0 &&
prop.CanWrite && !ShoudBeIgnored(prop) &&
!propertyNames.Contains(prop.Name) &&
!prop.PropertyType.IsValueType &&
CanBeResolved(prop))
{
yield return CreateSelectedProperty(context, prop);
}
}
}
示例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">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));
}
示例6: RemoveResolvers
/// <summary>
/// Remove the currently tracked resolvers from the given policy list.
/// </summary>
/// <param name="policies">Policy list to remove the resolvers from.</param>
public void RemoveResolvers(IPolicyList policies)
{
foreach(object key in keys)
{
policies.Clear<IDependencyResolverPolicy>(key);
}
keys.Clear();
}
示例7: 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
示例8: RemoveResolvers
/// <summary>
/// Remove the resolvers for the given build key.
/// </summary>
/// <param name="policies">Policy list containing the build key.</param>
/// <param name="buildKey">Build key.</param>
public static void RemoveResolvers(IPolicyList policies, object buildKey)
{
IDependencyResolverTrackerPolicy tracker = policies.Get<IDependencyResolverTrackerPolicy>(buildKey);
if (tracker != null)
{
tracker.RemoveResolvers(policies);
}
}
示例9: 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));
}
示例10: 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 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)
{
MethodInfo methodInfo = this.FindMethod(implementationType);
this.ValidateMethodCanBeInjected(methodInfo, implementationType);
SpecifiedMethodsSelectorPolicy selector =
GetSelectorPolicy(policies, implementationType, name);
selector.AddMethodAndParameters(methodInfo, this.methodParameters);
}
示例11: GetMappedType
private Type GetMappedType(IPolicyList policies)
{
var mappingPolicy = policies.Get<IBuildKeyMappingPolicy>(buildKey);
if (mappingPolicy != null)
{
return mappingPolicy.Map(buildKey, null).Type;
}
return buildKey.Type;
}
示例12: BuilderContext
/// <summary>
/// Create a new <see cref="BuilderContext"/> using the explicitly provided
/// values.
/// </summary>
/// <param name="chain">The <see cref="IStrategyChain"/> to use for this context.</param>
/// <param name="lifetime">The <see cref="ILifetimeContainer"/> to use for this context.</param>
/// <param name="persistentPolicies">The set of persistent policies to use for this context.</param>
/// <param name="transientPolicies">The set of transient policies to use for this context. It is
/// the caller's responsibility to ensure that the transient and persistent policies are properly
/// combined.</param>
/// <param name="buildKey">Build key for this context.</param>
/// <param name="existing">Existing object to build up.</param>
public BuilderContext(IStrategyChain chain, ILifetimeContainer lifetime, IPolicyList persistentPolicies, IPolicyList transientPolicies, NamedTypeBuildKey buildKey, object existing)
{
this.chain = chain;
this.lifetime = lifetime;
this.persistentPolicies = persistentPolicies;
this.policies = transientPolicies;
this.originalBuildKey = buildKey;
this.BuildKey = buildKey;
this.Existing = existing;
}
示例13: GetSelectorPolicy
private static SpecifiedMethodsSelectorPolicy GetSelectorPolicy(IPolicyList policies, Type typeToCreate, string name)
{
var key = new NamedTypeBuildKey(typeToCreate, name);
var selector = policies.GetNoDefault<IMethodSelectorPolicy>(key, false);
if (selector == null || !(selector is SpecifiedMethodsSelectorPolicy))
{
selector = new SpecifiedMethodsSelectorPolicy();
policies.Set<IMethodSelectorPolicy>(selector, key);
}
return (SpecifiedMethodsSelectorPolicy)selector;
}
示例14: BuilderContext
/// <summary>
/// Create a new <see cref="BuilderContext"/> using the explicitly provided
/// values.
/// </summary>
/// <param name="chain">The <see cref="IStrategyChain"/> to use for this context.</param>
/// <param name="locator">The <see cref="IReadWriteLocator"/> to use for this context.</param>
/// <param name="lifetime">The <see cref="ILifetimeContainer"/> to use for this context.</param>
/// <param name="persistentPolicies">The set of persistent policies to use for this context.</param>
/// <param name="transientPolicies">The set of transient policies to use for this context. It is
/// the caller's responsibility to ensure that the transient and persistent policies are properly
/// combined.</param>
/// <param name="buildKey">Build key for this context.</param>
/// <param name="existing">Existing object to build up.</param>
public BuilderContext(IStrategyChain chain, IReadWriteLocator locator, ILifetimeContainer lifetime, IPolicyList persistentPolicies, IPolicyList transientPolicies, object buildKey, object existing)
{
this.chain = chain;
this.lifetime = lifetime;
this.locator = locator;
this.persistentPolicies = persistentPolicies;
this.policies = transientPolicies;
this.originalBuildKey = buildKey;
this.buildKey = buildKey;
this.existing = existing;
}
示例15: 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);
}
}