public override ObjectBuilderState TryGetFirstValid(IInjectionTargetInfo targetInfo, out ObjectBuilder builder)
        {
            builder = null;
            if (_candidates.Count == 0)
            {
                return(ObjectBuilderState.Unregistered);
            }

            foreach (var candidate in _candidates)
            {
                var candidateBuilder = candidate.ObjectBuilder;
                if (!candidateBuilder.MatchCondition(targetInfo) || candidateBuilder.Obsolete)
                {
                    continue;
                }

                if (builder == null)
                {
                    builder = candidateBuilder;
                }
                else
                {
                    throw AmbiguousObjectBuilderException(true);
                }
            }

            return(builder != null ? ObjectBuilderState.Normal : ObjectBuilderState.Invalid);
        }
        public override List <ObjectBuilder> GetAllValid(IInjectionTargetInfo targetInfo)
        {
            var builder = MyRegistration.ObjectBuilder;

            return(!builder.MatchCondition(targetInfo) || builder.Obsolete
                ? null
                : new List <ObjectBuilder> {
                builder
            });
        }
        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();
            }
        }
        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();
            }
        }
        public ObjectCollectionObserver(ObjectBuilderGroup group, List <ObjectBuilder> builders, IInjectionTargetInfo targetInfo)
            : base(group)
        {
            if (SystemHelper.MultiProcessors)
            {
                _lock = new SpinLockSlim();
            }
            else
            {
                _lock = new MonitorLock();
            }

            _builders   = builders;
            _targetInfo = targetInfo;
        }
Esempio n. 6
0
        public bool Match(IInjectionTargetInfo targetInfo)
        {
            if (targetInfo == null)
            {
                return(false);
            }
            var targetType = targetInfo.TargetDescription.ConcreteType;

            foreach (var expectedType in _expectedTypes)
            {
                if (targetType == expectedType)
                {
                    return(true);
                }
            }
            return(false);
        }
        public bool TryGet(Type injectable, IInjectionTargetInfo targetInfo, out ObjectCollectionObserver observer)
        {
            Requires.NotNull(injectable, "injectable");
            Requires.NotNull(targetInfo, "info");
            ObjectBuilderGroup   group;
            List <ObjectBuilder> builders;

            if (!TryGetCore(injectable, targetInfo, out group, out builders))
            {
                observer = null;
                return(false);
            }
            var obs = new ObjectCollectionObserver(group, builders, targetInfo);

            group.AddObserver(obs);
            observer = obs;
            return(true);
        }
        internal static DependencyProvider CreateAutowiredDependencyProvider(IInjectionTargetInfo injectionTargetInfo, bool strongTyped)
        {
            if (!strongTyped)
            {
                return(new WeakAutowiredDependencyProvider(injectionTargetInfo));
            }
            var strongDependencyProviderType =
                typeof(StrongAutowiredDependencyProvider <>).MakeGenericType(injectionTargetInfo.TargetType);

            try
            {
                return((DependencyProvider)Activator.CreateInstance(strongDependencyProviderType, injectionTargetInfo));
            }
            catch (TargetInvocationException ex)
            {
                throw ex.InnerException;
            }
        }
        public override ObjectBuilderState TryGetFirstValid(IInjectionTargetInfo targetInfo, out ObjectBuilder builder)
        {
            builder = null;
            if (MyRegistration == null)
            {
                return(ObjectBuilderState.Unregistered);
            }

            var myBuilder = MyRegistration.ObjectBuilder;

            if (!myBuilder.MatchCondition(targetInfo) || myBuilder.Obsolete)
            {
                return(ObjectBuilderState.Invalid);
            }

            builder = myBuilder;
            return(ObjectBuilderState.Normal);
        }
        public override List <ObjectBuilder> GetAllValid(IInjectionTargetInfo targetInfo)
        {
            List <ObjectBuilder> builders = null;

            foreach (var candidate in _candidates)
            {
                var candidateBuilder = candidate.ObjectBuilder;
                if (!candidateBuilder.MatchCondition(targetInfo) || candidateBuilder.Obsolete)
                {
                    continue;
                }

                if (builders == null)
                {
                    builders = new List <ObjectBuilder>();
                }
                builders.Add(candidateBuilder);
            }
            return(builders);
        }
        ObjectBuilder DoGetObjectBuilder(Type concreteType, IInjectionTargetInfo injectionTargetInfo)
        {
            if (_registrationPolicies == null || !concreteType.IsConcrete())
            {
                return(null);
            }

            IAutoRegistrationPolicy matchPolicy = null;

            for (int i = 0; i < _registrationPolicies.Length; i++)
            {
                var autoRegistrationPolicy = _registrationPolicies[i];
                if (!autoRegistrationPolicy.ShouldRegister(concreteType))
                {
                    continue;
                }
                matchPolicy = autoRegistrationPolicy;
                break;
            }

            if (matchPolicy == null)
            {
                return(null);
            }

            IObjectRegistration registration;

            _registrar.Register(concreteType).In(matchPolicy.GetLifetimeProvider()).Return(out registration);
            if (!registration.ObjectBuilder.MatchCondition(injectionTargetInfo))
            {
                return(null);
            }

            _registrar.CommitRegistrations();
            return(registration.ObjectBuilder);
        }
Esempio n. 12
0
 protected DependencyResolverBase(IInjectionTargetInfo targetInfo)
 {
     MyTargetInfo = targetInfo;
 }
Esempio n. 13
0
 public WeakDependencyResolver(IInjectionTargetInfo targetInfo)
     : base(targetInfo)
 {
 }
Esempio n. 14
0
 protected CollectionDependencyResolver(IInjectionTargetInfo targetInfo, IObjectMapper mapper)
     : this(targetInfo, mapper, null)
 {
 }
Esempio n. 15
0
 protected CollectionDependencyResolver(IInjectionTargetInfo targetInfo, IObjectMapper mapper, ObjectCollectionObserver observer)
     : base(targetInfo)
 {
     MyMapper   = mapper;
     MyObserver = observer;
 }
Esempio n. 16
0
 public virtual void Dispose()
 {
     MyTargetInfo = null;
 }
 internal abstract bool MatchCondition(IInjectionTargetInfo targetInfo);
            public ParameterExpression GetLocateDependencyExpression(Type importType = null,
                string importName = null,
                IInjectionTargetInfo targetInfo = null,
                string variableName = null,
                bool isRequired = true,
                IExportValueProvider valueProvider = null,
                ExportStrategyFilter exportStrategyFilter = null,
                ILocateKeyValueProvider locateKey = null,
                object comparerObject = null)
            {
                if (importType == null && importName == null)
                {
                    throw new ArgumentException("GetLocateDependencyExpression must be called with importType or ");
                }

                return null;
            }
Esempio n. 19
0
 public MappableStrongDependencyResolver(IInjectionTargetInfo targetInfo, IObjectMapper mapper)
     : base(targetInfo)
 {
     _mapper = mapper;
 }
Esempio n. 20
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="locateName">name used to locate</param>
 /// <param name="locateType">type used to locate</param>
 /// <param name="targetInfo"></param>
 public LocationInformationEntry(string locateName, TypeWrapper locateType, IInjectionTargetInfo targetInfo)
 {
     TargetInfo = targetInfo;
     LocateName = locateName;
     LocateType = locateType;
 }
 public ObjectBuilderState TryGet(Type injectable, IInjectionTargetInfo targetInfo, out ObjectBuilder builder)
 {
     Requires.NotNull(injectable, "injectable");
     Requires.NotNull(targetInfo, "info");
     return(TryGetCore(injectable, targetInfo, out builder));
 }
Esempio n. 22
0
 public bool Match(IInjectionTargetInfo targetInfo)
 {
     return(targetInfo != null && _condition.Invoke(targetInfo));
 }
        ObjectBuilderState TryGetCore(Type contract, IInjectionTargetInfo targetInfo, out ObjectBuilder builder)
        {
            ObjectBuilderGroup group;

            return(TryGetCore(contract, targetInfo, out group, out builder));
        }
Esempio n. 24
0
 public bool Match(IInjectionTargetInfo targetInfo)
 {
     return(targetInfo != null &&
            (_expectedType == targetInfo.TargetDescription.ConcreteType ||
             _expectedType.IsAssignableFrom(targetInfo.TargetDescription.ConcreteType)));
 }
Esempio n. 25
0
 public MappableWeakDependencyResolver(IInjectionTargetInfo targetInfo, IObjectMapper mapper)
     : base(targetInfo)
 {
     MyMapper = mapper;
 }
Esempio n. 26
0
 public bool Match(IInjectionTargetInfo targetInfo)
 {
     return(targetInfo != null && _metadata.Equals(targetInfo.TargetDescription.Metadata));
 }
Esempio n. 27
0
 public StrongDependencyResolver(IInjectionTargetInfo targetInfo)
     : base(targetInfo)
 {
 }
 internal static DependencyProvider CreateAutowiredDependencyProvider <TParam>(IInjectionTargetInfo injectionTargetInfo)
 {
     return(new StrongAutowiredDependencyProvider <TParam>(injectionTargetInfo));
 }
Esempio n. 29
0
 public MappableStrongCollectionDependencyResolver(IInjectionTargetInfo targetInfo, IObjectMapper mapper)
     : base(targetInfo, mapper)
 {
 }
 internal static DependencyProvider CreateAutowiredDependencyProvider(IInjectionTargetInfo injectionTargetInfo)
 {
     return(new WeakAutowiredDependencyProvider(injectionTargetInfo));
 }
Esempio n. 31
0
 protected SingleDependencyResolver(IInjectionTargetInfo targetInfo)
     : base(targetInfo)
 {
 }
 internal override bool MatchCondition(IInjectionTargetInfo targetInfo)
 {
     return(_condition.Match(targetInfo) && base.MatchCondition(targetInfo));
 }