Example #1
0
        internal void Add(Type type, ContainerInstance instance)
        {
            this.CheckDisposed();

            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            lock (this.registractionContextLocker)
            {
                if (this.currentRegistrationContext == null)
                {
                    throw new NotSupportedException(
                              InversionOfControlResources.ErrMsg_ContainerIsNotBlockedForRegistration);
                }

                this.registeredObjects.Add(type, instance);
            }
        }
Example #2
0
        /// <inheritdoc />
        public object Resolve(Type type, params object[] arguments)
        {
            ContainerInstance instance = this.Get(type);

            if (instance != null)
            {
                return(instance.Resolve(arguments));
            }

            if (this.Behavior.AutoRegistration)
            {
                if (this.parentContainer == null || !this.parentContainer.IsRegistered(type))
                {
                    using (var registration = this.Registration())
                    {
                        instance = (ContainerInstance)registration.Register(type);
                    }

                    return(instance.Resolve(arguments));
                }
            }

            if (this.parentContainer != null)
            {
                return(this.parentContainer.Resolve(type, arguments));
            }

            throw new ArgumentOutOfRangeException(
                      "type",
                      string.Format(CultureInfo.CurrentCulture, InversionOfControlResources.ErrMsg_TypeIsNotRegistered, type));
        }
            public InjectInfo(Type type, ContainerInstance containerInstance)
            {
                if (type == null)
                {
                    throw new ArgumentNullException("type");
                }

                this.Type = type;
                this.ContainerInstance = containerInstance;
            }