bool TryGetCore(Type contract, IInjectionTargetInfo targetInfo, out ObjectBuilderGroup group, out List <ObjectBuilder> builders)
        {
            var key = GetKey(contract);

            _operationLock.EnterReadLock();
            try
            {
                if (_key2Groups.TryGetValue(key, out group))
                {
                    builders = targetInfo != null
                        ? group.GetAllValid(targetInfo)
                        : group.GetAllValid();

                    if (builders != null)
                    {
                        return(true);
                    }
                }
            }
            finally
            {
                _operationLock.ExitReadLock();
            }

            var args = new ObjectRequestedEventArgs(_kernel, contract, targetInfo);

            if (!HandleObjectBuilderRequest(args))
            {
                builders = null;
                return(false);
            }

            _operationLock.EnterReadLock();
            try
            {
                if (group == null && !_key2Groups.TryGetValue(key, out group))
                {
                    builders = null;
                    return(false);
                }
                builders = targetInfo != null
                    ? group.GetAllValid(targetInfo)
                    : group.GetAllValid();

                return(builders != null);
            }
            finally
            {
                _operationLock.ExitReadLock();
            }
        }
示例#2
0
        void AddRegistration(IObjectRegistration registration, ref List <IOperation> operations)
        {
            var key = GetKey(registration.ObjectDescription.ContractType);
            ObjectBuilderGroup group;

            if (!_key2Groups.TryGetValue(key, out group))
            {
                group = new ObjectBuilderGroup();
                _key2Groups.Add(key, group);
            }
            group.Add(registration);

            var relation = registration.ObjectBuilder.ObjectRelation;

            relation.RegistrationState  = RegistrationState.Registered;
            relation.ObjectBuilderGroup = group;
            operations.Add(new RegistrationOperation(relation));
        }
        ObjectBuilderState TryGetCore(Type contract, IInjectionTargetInfo targetInfo, out ObjectBuilderGroup group, out ObjectBuilder builder)
        {
            var result = ObjectBuilderState.Unregistered;
            var key    = GetKey(contract);

            _operationLock.EnterReadLock();
            try
            {
                if (_key2Groups.TryGetValue(key, out group))
                {
                    result = targetInfo != null
                        ? group.TryGetFirstValid(targetInfo, out builder)
                        : group.TryGetFirstValid(out builder);

                    if (result == ObjectBuilderState.Normal)
                    {
                        return(result);
                    }
                }
            }
            finally
            {
                _operationLock.ExitReadLock();
            }

            var args = new ObjectRequestedEventArgs(_kernel, contract, targetInfo);

            if (!HandleObjectBuilderRequest(args))
            {
                builder = null;
                return(result);
            }

            _operationLock.EnterReadLock();
            try
            {
                if (group == null && !_key2Groups.TryGetValue(key, out group))
                {
                    builder = null;
                    return(result);
                }
                return(targetInfo != null
                    ? group.TryGetFirstValid(targetInfo, out builder)
                    : group.TryGetFirstValid(out builder));
            }
            finally
            {
                _operationLock.ExitReadLock();
            }
        }