Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
        public ObjectExtender(IMetaInfoProvider metaInfoProvider, InjectionParameter[] injectionParameters = null)
        {
            if (injectionParameters != null)
                this.injectionParameters = injectionParameters;

            this.metaInfoProvider = metaInfoProvider;
        }
Ejemplo n.º 3
0
 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);
     }
 }
Ejemplo n.º 4
0
 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
         });
 }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
        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
            };
        }
Ejemplo n.º 7
0
        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;
        }
Ejemplo n.º 8
0
 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
        });
 }
Ejemplo n.º 9
0
        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)));
        }
Ejemplo n.º 10
0
 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()
     };
 }
Ejemplo n.º 11
0
 public bool TryChooseConstructor(out ResolutionConstructor resolutionConstructor, ResolutionInfo resolutionInfo, InjectionParameter[] injectionParameters = null)
 {
     return this.TryGetBestConstructor(out resolutionConstructor, resolutionInfo, injectionParameters);
 }
Ejemplo n.º 12
0
        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;
        }
Ejemplo n.º 13
0
 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);
 }
Ejemplo n.º 14
0
 public bool CanResolve(IContainerContext containerContext, TypeInformation typeInformation,
     InjectionParameter[] injectionParameters)
 {
     return this.resolverSelector.CanResolve(containerContext, typeInformation) ||
                                   (injectionParameters != null &&
                                    injectionParameters.Any(injectionParameter =>
                                    injectionParameter.Name == typeInformation.MemberName));
 }
Ejemplo n.º 15
0
        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;
            }
        }