Exemplo n.º 1
0
        /// <summary>
        /// Implements the <see cref="IContainerConfig.Configure(Container, IRootTargetContainer)"/> method,
        /// registering all the targets necessary to use expression-based compilation for all the standard targets
        /// defined in the <c>Rezolver</c> core library.
        /// </summary>
        /// <param name="container">The container - ignored.</param>
        /// <param name="targets">Required - the target container into which the various targets will be registered.</param>
        /// <remarks>All targets registered by this function are <see cref="ObjectTarget"/> targets backed by concrete instances
        /// of the various components (compiler etc).</remarks>
        public virtual void Configure(Container container, IRootTargetContainer targets)
        {
            if (targets == null)
            {
                throw new ArgumentNullException(nameof(targets));
            }
            // note - the singleton container is done like this because the expression compiler which uses
            // it Resolves it from the container during compilation.  This is to ensure that each container
            // gets the same singleton container (including OverridingContainer), rather than a single shared one
            // from the target container option.
            targets.RegisterObject(new SingletonTarget.SingletonContainer());
            // targets.RegisterObject(new ExpressionBuilderCache(container));
            // will be how containers pick up and use this compiler
            targets.SetOption <ITargetCompiler>(ExpressionCompiler.Default);
            // if you're looking to re-enter the compilation process for a particular
            // target - then you should request our compiler via the type IExpressionCompiler
            targets.SetOption <IExpressionCompiler>(ExpressionCompiler.Default);

            // loop through all the types in the core Rezolver assembly's Rezolver.Targets namespace, searching for an implementing
            // type in this assembly
            foreach (var registration in GetStandardTargetBuilders())
            {
                targets.SetOption(registration.Instance, registration.TargetType);
            }
        }
 public EnumerableTargetContainer(IRootTargetContainer root)
     : base(root, typeof(IEnumerable <>))
 {
     this._tracker = root.GetOption <TargetOrderTracker>();
     if (this._tracker == null)
     {
         // this is the first enumerable container in the root
         // so create the tracker and register our own event handler
         // for adding enumerable types.
         root.SetOption(this._tracker = new TargetOrderTracker(Root));
         Root.TargetRegistered       += Root_TargetRegistered;
     }
 }
Exemplo 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);
        }