public bool CanResolve(IContainerContext containerContext, TypeInformation typeInformation,
     InjectionParameter[] injectionParameters)
 {
     return this.resolutionStrategy.CanResolve(containerContext, typeInformation, injectionParameters) ||
            this.resolutionStrategy.CanResolve(containerContext.Container.ParentContainer.ContainerContext, typeInformation,
                injectionParameters);
 }
Exemple #2
0
        public ObjectExtender(IMetaInfoProvider metaInfoProvider, InjectionParameter[] injectionParameters = null)
        {
            if (injectionParameters != null)
                this.injectionParameters = injectionParameters;

            this.metaInfoProvider = metaInfoProvider;
        }
 public void ExecuteOnRegistrationExtensions(IContainerContext containerContext, RegistrationInfo registrationInfo, InjectionParameter[] injectionParameters = null)
 {
     if (!this.hasRegistrationExtensions) return;
     using (this.readerWriterLock.AcquireReadLock())
     {
         foreach (var extension in this.registrationExtensions)
             extension.OnRegistration(containerContext, registrationInfo, injectionParameters);
     }
 }
 public IEnumerable<ResolutionMember> GetResolutionMembers(InjectionParameter[] injectionParameters = null)
 {
     return this.metaInfoCache.InjectionMembers.Where(propertyInfo =>
            containerContext.ResolutionStrategy.CanResolve(containerContext, propertyInfo.TypeInformation, injectionParameters))
         .Select(memberInfo => new ResolutionMember
         {
             ResolutionTarget = containerContext.ResolutionStrategy.BuildResolutionTarget(containerContext, memberInfo.TypeInformation, injectionParameters),
             MemberSetter = memberInfo.MemberInfo.GetMemberSetter(),
             MemberInfo = memberInfo.MemberInfo
         });
 }
        public ResolutionTarget BuildResolutionTarget(IContainerContext containerContext, TypeInformation typeInformation,
            InjectionParameter[] injectionParameters)
        {
            var target = this.resolutionStrategy.BuildResolutionTarget(containerContext, typeInformation,
                injectionParameters);

            if (target.Resolver == null && target.ResolutionTargetValue == null)
                return this.resolutionStrategy.BuildResolutionTarget(
                    containerContext.Container.ParentContainer.ContainerContext, typeInformation, injectionParameters);
            else
                return target;
        }
        public ResolutionTarget BuildResolutionTarget(IContainerContext containerContext, TypeInformation typeInformation,
            InjectionParameter[] injectionParameters)
        {
            Resolver resolver;
            this.resolverSelector.TryChooseResolver(containerContext, typeInformation, out resolver);

            return new ResolutionTarget
            {
                Resolver = resolver,
                TypeInformation = typeInformation,
                ResolutionTargetValue = injectionParameters?.FirstOrDefault(param => param.Name == typeInformation.MemberName)?.Value
            };
        }
        public DefaultObjectBuilder(IContainerContext containerContext, IMetaInfoProvider metaInfoProvider,
            IContainerExtensionManager containerExtensionManager, string registrationName,
            InjectionParameter[] injectionParameters = null)
        {
            if (injectionParameters != null)
                this.injectionParameters = injectionParameters;

            this.instanceType = metaInfoProvider.TypeTo;
            this.containerExtensionManager = containerExtensionManager;
            this.registrationName = registrationName;
            this.metaInfoProvider = metaInfoProvider;
            this.containerContext = containerContext;
        }
 public IEnumerable<ResolutionMethod> GetResolutionMethods(InjectionParameter[] injectionParameters = null)
 {
     return this.metaInfoCache.InjectionMethods
         .Where(methodInfo => methodInfo.Parameters.All(parameter =>
                          containerContext.ResolutionStrategy.CanResolve(containerContext, parameter, injectionParameters)))
        .Select(methodInfo => new ResolutionMethod
        {
        MethodDelegate = ExpressionDelegateFactory.CreateMethodExpression(this.containerContext,
          methodInfo.Parameters.Select(parameter =>
             this.containerContext.ResolutionStrategy.BuildResolutionTarget(this.containerContext, parameter, injectionParameters)).ToArray(),
         methodInfo.Method),
        Method = methodInfo.Method
        });
 }
        private IEnumerable<ConstructorInformation> GetUsableConstructors(IEnumerable<ConstructorInformation> constructors, ResolutionInfo resolutionInfo,
            InjectionParameter[] injectionParameters = null)
        {
            if (resolutionInfo?.OverrideManager == null)
                return constructors
                    .Where(constructor => constructor.Parameters
                        .All(parameter => this.containerContext.ResolutionStrategy.CanResolve(this.containerContext, parameter,
                        injectionParameters)));

            return constructors
                .Where(constructor => constructor.Parameters
                    .All(parameter => this.containerContext.ResolutionStrategy.CanResolve(this.containerContext, parameter,
                        injectionParameters) ||
                         resolutionInfo.OverrideManager.ContainsValue(parameter)));
        }
 private ResolutionConstructor CreateResolutionConstructor(ConstructorInformation constructorInformation, InjectionParameter[] injectionParameters = null)
 {
     return new ResolutionConstructor
     {
         Constructor = constructorInformation.Constructor,
         Parameters = constructorInformation.Parameters.Select(parameter => this.containerContext.ResolutionStrategy.BuildResolutionTarget(this.containerContext, parameter, injectionParameters)).ToArray()
     };
 }
 public bool TryChooseConstructor(out ResolutionConstructor resolutionConstructor, ResolutionInfo resolutionInfo, InjectionParameter[] injectionParameters = null)
 {
     return this.TryGetBestConstructor(out resolutionConstructor, resolutionInfo, injectionParameters);
 }
        private bool TryGetConstructor(IEnumerable<ConstructorInformation> constructors, out ResolutionConstructor resolutionConstructor,
            ResolutionInfo resolutionInfo, InjectionParameter[] injectionParameters = null)
        {
            var usableConstructors = this.GetUsableConstructors(constructors, resolutionInfo, injectionParameters).ToArray();

            if (usableConstructors.Any())
            {
                resolutionConstructor = this.CreateResolutionConstructor(this.SelectBestConstructor(usableConstructors), injectionParameters);
                return true;
            }

            resolutionConstructor = null;
            return false;
        }
 private bool TryGetBestConstructor(out ResolutionConstructor resolutionConstructor, ResolutionInfo resolutionInfo,
     InjectionParameter[] injectionParameters = null)
 {
     return this.TryGetConstructor(this.metaInfoCache.Constructors.Where(constructor => constructor.HasInjectionAttribute), out resolutionConstructor, resolutionInfo, injectionParameters) ||
         this.TryGetConstructor(this.metaInfoCache.Constructors.Where(constructor => !constructor.HasInjectionAttribute), out resolutionConstructor, resolutionInfo, injectionParameters);
 }
 public bool CanResolve(IContainerContext containerContext, TypeInformation typeInformation,
     InjectionParameter[] injectionParameters)
 {
     return this.resolverSelector.CanResolve(containerContext, typeInformation) ||
                                   (injectionParameters != null &&
                                    injectionParameters.Any(injectionParameter =>
                                    injectionParameter.Name == typeInformation.MemberName));
 }
        public object ExecutePostBuildExtensions(object instance, Type targetType, IContainerContext containerContext, ResolutionInfo resolutionInfo, 
            TypeInformation resolveType, InjectionParameter[] injectionParameters = null)
        {
            if (!this.hasPostBuildExtensions) return instance;
            using (this.readerWriterLock.AcquireReadLock())
            {
                var result = instance;
                foreach (var extension in this.postbuildExtensions)
                    result = extension.PostBuild(instance, targetType, containerContext, resolutionInfo, resolveType, injectionParameters);

                return result;
            }
        }