Ejemplo n.º 1
0
        /// <summary>
        /// Adds the necessary registration to the passed root target container
        /// for <see cref="Lazy{T}"/> so long as no <see cref="ITargetContainer"/> is already
        /// registered.
        /// </summary>
        /// <param name="targets">The root target container to which this configuation will be applied.</param>
        public override void Configure(IRootTargetContainer targets)
        {
            if (targets == null)
            {
                throw new ArgumentNullException(nameof(targets));
            }

            if (!targets.GetOption <EnableAutoLazyInjection>())
            {
                return;
            }

            if (targets.FetchContainer(typeof(Lazy <>)) == null)
            {
                targets.RegisterContainer(typeof(Lazy <>), new AutoLazyTargetContainer(targets));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Implementation of <see cref="OptionDependentConfigBase.Configure(IRootTargetContainer)"/>
        /// </summary>
        /// <param name="targets"></param>
        /// <remarks>
        /// This implementation registers a special target container (via <see cref="ITargetContainer.RegisterContainer(Type, ITargetContainer)"/>)
        /// for <see cref="IEnumerable{T}"/> in passed <paramref name="targets"/>
        /// if the <see cref="Options.EnableEnumerableInjection"/> option evaluates to <c>true</c> when read from <paramref name="targets"/>.
        ///
        /// This is the default value for that option anyway, so, as the remarks section on the class states, all that's required to enable
        /// the enumerable resolving behaviour is simply to make sure this configuration object is applied to an <see cref="IRootTargetContainer"/></remarks>
        public override void Configure(IRootTargetContainer targets)
        {
            if (targets == null)
            {
                throw new ArgumentNullException(nameof(targets));
            }
            // if an option has already been set on the target container which disables automatic enumerables,
            // then do not apply the configuration.
            if (!targets.GetOption(Options.EnableEnumerableInjection.Default))
            {
                return;
            }

            if (targets.FetchContainer(typeof(IEnumerable <>)) == null)
            {
                targets.RegisterContainer(typeof(IEnumerable <>), new EnumerableTargetContainer(targets));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Implements the <see cref="OptionDependentConfigBase.Configure(IRootTargetContainer)"/> abstract method
        /// by configuring the passed <paramref name="targets"/> so it can produce targets for any array type, regardless
        /// of whether a single object has been registered for the array's element type.
        ///
        /// After enabling, the ability to register specific targets for concrete array types will still be present.
        /// </summary>
        /// <param name="targets"></param>
        public override void Configure(IRootTargetContainer targets)
        {
            if (targets == null)
            {
                throw new ArgumentNullException(nameof(targets));
            }

            // REVIEW: should this also check that EnableEnumerableInjection is true?
            // At the moment, it's just dependent upon the Enumerable config; but it actually needs it to
            // be *enabled* too.

            if (!targets.GetOption(Options.EnableArrayInjection.Default))
            {
                return;
            }

            targets.RegisterContainer(typeof(Array), new ArrayTargetContainer(targets));
            targets.SetOption <ITargetContainerTypeResolver, Array>(ArrayTypeResolver.Instance);
        }
 private static void RegisterProjectionInternal(this IRootTargetContainer targets, Type fromType, Type toType, Func <IRootTargetContainer, ITarget, TargetProjection> projectionFactory)
 {
     targets.RegisterContainer(typeof(IEnumerable <>).MakeGenericType(toType),
                               new ProjectionTargetContainer(targets, fromType, toType, projectionFactory));
 }