本文整理汇总了C#中NamedTypeBuildKey类的典型用法代码示例。如果您正苦于以下问题:C# NamedTypeBuildKey类的具体用法?C# NamedTypeBuildKey怎么用?C# NamedTypeBuildKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NamedTypeBuildKey类属于命名空间,在下文中一共展示了NamedTypeBuildKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResolvedAutoInterceptorPolicy
/// <summary>
///
/// </summary>
/// <param name="interceptorResolver"></param>
/// <param name="buildKey"></param>
public ResolvedAutoInterceptorPolicy(Func<NamedTypeBuildKey, IInstanceInterceptor> interceptorResolver, NamedTypeBuildKey buildKey)
{
Guard.ArgumentNotNull(interceptorResolver, "interceptorResolver");
Guard.ArgumentNotNull(buildKey, "buildKey");
this.BuildKey = buildKey;
this.InterceptorResolver = interceptorResolver;
}
示例2: ConfigureContainer
/// <summary>
/// Configures the container.
/// </summary>
/// <param name="container">The container.</param>
protected override void ConfigureContainer(IUnityContainer container)
{
if (Interceptor == null)
{
return;
}
var interceptorType = TypeResolver.ResolveType(Interceptor.TypeName);
if (!typeof (IInstanceInterceptor).IsAssignableFrom(interceptorType))
{
throw new ConfigurationErrorsException(Resources.ExceptionOnlyInstanceInterceptorBeSupported);
}
var builderName = interceptorType.AssemblyQualifiedName;
var source =
Interceptor.Injection.SelectMany(
(InjectionMemberElement element) =>
element.GetInjectionMembers(container, typeof (IInstanceInterceptor), interceptorType,
builderName));
container.RegisterType(typeof (IInstanceInterceptor), interceptorType, builderName,
new ContainerControlledLifetimeManager(), source.ToArray());
var buildKey = new NamedTypeBuildKey(typeof (IInstanceInterceptor), builderName);
var instance =
new ResolvedAutoInterceptorPolicy(
(NamedTypeBuildKey key) => container.Resolve<IInstanceInterceptor>(key.Name), buildKey);
container.RegisterInstance(typeof (AutoInterceptorPolicy),
typeof (AutoInterceptorPolicy).AssemblyQualifiedName, instance, new ContainerControlledLifetimeManager());
}
示例3: Resolve
public object Resolve(IBuilderContext context)
{
Guard.ArgumentNotNull(context, "context");
NamedTypeBuildKey key = new NamedTypeBuildKey(type, name);
IBuilderContext recursiveContext = context.CloneForNewBuild(key, null);
return recursiveContext.Strategies.ExecuteBuildUp(recursiveContext);
}
示例4: ContainerRegistration
internal ContainerRegistration(Type registeredType, string name, IPolicyList policies)
{
this.buildKey = new NamedTypeBuildKey(registeredType, name);
MappedToType = GetMappedType(policies);
LifetimeManagerType = GetLifetimeManagerType(policies);
LifetimeManager = GetLifetimeManager(policies);
}
示例5: Interceptor
/// <summary>
/// Initialize a new instance of the <see cref="Interceptor"/> class with a given
/// name and type that will be resolved to provide interception.
/// </summary>
/// <param name="interceptorType">Type of the interceptor</param>
/// <param name="name">name to use to resolve.</param>
public Interceptor(Type interceptorType, string name)
{
Guard.ArgumentNotNull(interceptorType, "interceptorType");
Guard.TypeIsAssignable(typeof(IInterceptor), interceptorType, "interceptorType");
buildKey = new NamedTypeBuildKey(interceptorType, name);
}
示例6: 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
示例7: OnRegisterInstance
private void OnRegisterInstance(object sender, RegisterInstanceEventArgs e)
{
Context.RegisterNamedType(e.RegisteredType, e.Name);
SetLifetimeManager(e.RegisteredType, e.Name, e.LifetimeManager);
NamedTypeBuildKey identityKey = new NamedTypeBuildKey(e.RegisteredType, e.Name);
Context.Policies.Set<IBuildKeyMappingPolicy>(new BuildKeyMappingPolicy(identityKey), identityKey);
e.LifetimeManager.SetValue(e.Instance);
}
示例8: Resolve
/// <summary>
/// Get the value for a dependency.
/// </summary>
/// <param name="context">Current build context.</param>
/// <returns>The value for the dependency.</returns>
public object Resolve(IBuilderContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
var buildKey = new NamedTypeBuildKey(typeToBuild);
return context.NewBuildUp(buildKey);
}
示例9: Map
/// <summary>
/// Maps the build key.
/// </summary>
/// <param name="buildKey">The build key to map.</param>
/// <param name="context">Current build context. Used for contextual information
/// if writing a more sophisticated mapping.</param>
/// <returns>The new build key.</returns>
public NamedTypeBuildKey Map(NamedTypeBuildKey buildKey, IBuilderContext context)
{
Guard.ArgumentNotNull(buildKey, "buildKey");
Type originalType = buildKey.Type;
GuardSameNumberOfGenericArguments(originalType);
Type[] genericArguments = originalType.GetGenericArguments();
Type resultType = destinationKey.Type.MakeGenericType(genericArguments);
return new NamedTypeBuildKey(resultType, destinationKey.Name);
}
示例10: CanMapGenericTypeFromNamedTypeBuildKey
public void CanMapGenericTypeFromNamedTypeBuildKey()
{
NamedTypeBuildKey original = new NamedTypeBuildKey(typeof (IList<string>), "test");
IBuildKeyMappingPolicy policy = new GenericTypeBuildKeyMappingPolicy(new NamedTypeBuildKey(typeof (List<>), "test"));
NamedTypeBuildKey result = policy.Map(original, null);
Assert.AreEqual(typeof (List<string>), result.Type);
Assert.AreEqual(original.Name, result.Name);
}
示例11: GetContext
private IBuilderContext GetContext(IBuilderContext originalContext, NamedTypeBuildKey buildKey, DynamicBuildPlanGenerationContext ilContext)
{
return new BuilderContext(
strategies.MakeStrategyChain(),
originalContext.Lifetime,
originalContext.PersistentPolicies,
originalContext.Policies,
buildKey,
ilContext);
}
示例12: CanMapGenericTypeToNewGenericType
public void CanMapGenericTypeToNewGenericType()
{
var original = new NamedTypeBuildKey(typeof (IList<int>));
var expected = new NamedTypeBuildKey(typeof (List<int>));
IBuildKeyMappingPolicy policy = new GenericTypeBuildKeyMappingPolicy(new NamedTypeBuildKey(typeof (List<>)));
var result = policy.Map(original, null);
Assert.AreEqual(expected, result);
}
示例13: HasLifetimeFactoryPolicy
// Checks if the instance being resolved has a lifetime manager factory
private static bool HasLifetimeFactoryPolicy(IBuilderContext context)
{
var openGenericBuildKey = new NamedTypeBuildKey(context.BuildKey.Type.GetGenericTypeDefinition(),
context.BuildKey.Name);
IPolicyList factorySource;
var factoryPolicy = context.Policies.Get<ILifetimeFactoryPolicy>(openGenericBuildKey, out factorySource);
return factoryPolicy != null;
}
示例14: BuildTreeItemNode
public BuildTreeItemNode(NamedTypeBuildKey buildKey, Boolean nodeCreatedByContainer,
BuildTreeItemNode parentNode)
{
Contract.Requires<ArgumentNullException>(buildKey != null);
BuildKey = buildKey;
NodeCreatedByContainer = nodeCreatedByContainer;
Parent = parentNode;
Children = new Collection<BuildTreeItemNode>();
}
示例15: RequestIsForValidatorOfT
private static bool RequestIsForValidatorOfT(NamedTypeBuildKey key)
{
var typeToBuild = key.Type;
if(!typeToBuild.IsGenericType) return false;
if(typeToBuild.GetGenericTypeDefinition() != typeof(Validator<>)) return false;
return true;
}