Beispiel #1
0
        /// <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");

            var originalTypeInfo = buildKey.Type.GetTypeInfo();

            if (originalTypeInfo.IsGenericTypeDefinition)
            {
                // No need to perform a mapping - the source type is an open generic
                return(this.destinationKey);
            }

            this.GuardSameNumberOfGenericArguments(originalTypeInfo);
            Type[] genericArguments = originalTypeInfo.GenericTypeArguments;
            Type   resultType       = this.destinationKey.Type.MakeGenericType(genericArguments);

            return(new NamedTypeBuildKey(resultType, this.destinationKey.Name));
        }
Beispiel #2
0
 /// <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="resolverOverrides">The resolver overrides.</param>
 protected BuilderContext(IUnityContainer container, IStrategyChain chain, ILifetimeContainer lifetime, IPolicyList persistentPolicies, IPolicyList transientPolicies, NamedTypeBuildKey buildKey, CompositeResolverOverride resolverOverrides = null)
 {
     this.Container          = container;
     this.chain              = chain;
     this.lifetime           = lifetime;
     this.persistentPolicies = persistentPolicies;
     this.policies           = transientPolicies;
     this.originalBuildKey   = buildKey;
     this.BuildKey           = buildKey;
     this.Existing           = null;
     this.resolverOverrides  = resolverOverrides ?? new CompositeResolverOverride();;
     this.ownsOverrides      = null == resolverOverrides;
 }
Beispiel #3
0
 /// <summary>
 /// Initialize a new instance of the <see cref="BuilderContext"/> class with a <see cref="IStrategyChain"/>,
 /// <see cref="ILifetimeContainer"/>, <see cref="IPolicyList"/> and the
 /// build key used to start this build operation.
 /// </summary>
 /// <param name="container">The instance of <see cref="UnityContainer"/> it is associated with</param>
 /// <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="policies">The <see cref="IPolicyList"/> to use for this context.</param>
 /// <param name="originalBuildKey">Build key to start building.</param>
 /// <param name="existing">The existing object to build up.</param>
 public BuilderContext(IUnityContainer container, IStrategyChain chain, ILifetimeContainer lifetime, IPolicyList policies, NamedTypeBuildKey originalBuildKey, object existing)
 {
     this.Container          = container;
     this.chain              = chain;
     this.lifetime           = lifetime;
     this.originalBuildKey   = originalBuildKey;
     this.BuildKey           = originalBuildKey;
     this.persistentPolicies = policies;
     this.policies           = new PolicyList(persistentPolicies);
     this.Existing           = existing;
     this.resolverOverrides  = new CompositeResolverOverride();
     this.ownsOverrides      = true;
 }
Beispiel #4
0
 /// <summary>
 /// Create a new instance storing the given type.
 /// </summary>
 /// <param name="typeToBuild">Type to resolve.</param>
 public FixedTypeResolverPolicy(Type typeToBuild)
 {
     this.keyToBuild = new NamedTypeBuildKey(typeToBuild);
 }
Beispiel #5
0
 public static TResult NewBuildUp <TResult>(this IBuilderContext context, string name)
 {
     Guard.ArgumentNotNull(context, "context");
     return((TResult)context.NewBuildUp(NamedTypeBuildKey.Make <TResult>(name)));
 }