Exemple #1
0
        private MemberInformation[] ConstructInjectionMembers(RegistrationContextData registrationContextData, MetaInformation metaInfo)
        {
            if (registrationContextData.InjectionMemberNames.Count == 0)
            {
                return(metaInfo.InjectionMembers);
            }

            var length  = metaInfo.InjectionMembers.Length;
            var members = new MemberInformation[length];

            for (var i = 0; i < length; i++)
            {
                var member = metaInfo.InjectionMembers[i];
                if (registrationContextData.InjectionMemberNames.TryGetValue(member.MemberInfo.Name,
                                                                             out var dependencyName))
                {
                    var copy = member.Clone();
                    copy.TypeInformation.ForcedDependency = true;
                    copy.TypeInformation.DependencyName   = dependencyName;
                    members[i] = copy;
                }
                else
                {
                    members[i] = member;
                }
            }

            return(members);
        }
Exemple #2
0
        internal ServiceRegistration(Type implementationType, IContainerConfigurator containerConfigurator,
                                     IObjectBuilderSelector objectBuilderSelector, RegistrationContextData registrationContextData,
                                     bool isDecorator, bool shouldHandleDisposal)
        {
            this.containerConfigurator = containerConfigurator;
            this.objectBuilderSelector = objectBuilderSelector;
            this.ImplementationType    = implementationType;
            this.metaInformation       = MetaInformation.GetOrCreateMetaInfo(implementationType);
            this.Constructors          = this.metaInformation.GetConstructors();
            this.InjectionMethods      = this.metaInformation.GetInjectionMethods();
            this.InjectionMembers      = this.metaInformation.SelectInjectionMembers(registrationContextData,
                                                                                     containerConfigurator.ContainerConfiguration);
            this.SelectedConstructor  = this.metaInformation.FindSelectedConstructor(registrationContextData);
            this.RegistrationNumber   = ReserveRegistrationNumber();
            this.RegistrationContext  = registrationContextData;
            this.IsDecorator          = isDecorator;
            this.ShouldHandleDisposal = shouldHandleDisposal;

            this.HasName = this.RegistrationContext.Name != null;

            this.HasScopeName = this.RegistrationContext.Lifetime is NamedScopeLifetime;

            this.HasCondition = this.RegistrationContext.TargetTypeCondition != null || this.RegistrationContext.ResolutionCondition != null ||
                                this.RegistrationContext.AttributeConditions != null && this.RegistrationContext.AttributeConditions.Any();

            this.RegistrationId = this.RegistrationContext.Name ??
                                  (containerConfigurator.ContainerConfiguration.SetUniqueRegistrationNames
                ? (object)this.RegistrationNumber
                : implementationType);

            this.objectBuilder = this.SelectObjectBuilder();
        }
Exemple #3
0
        internal ServiceRegistration(Type serviceType, Type implementationType, IContainerConfigurator containerConfigurator,
                                     IObjectBuilder objectBuilder, RegistrationContextData registrationContextData,
                                     bool isDecorator, bool shouldHandleDisposal)
        {
            this.objectBuilder         = objectBuilder;
            this.containerConfigurator = containerConfigurator;
            this.ImplementationType    = implementationType;
            this.ServiceType           = serviceType;
            this.MetaInformation       = GetOrCreateMetaInfo(implementationType, registrationContextData);
            this.RegistrationNumber    = ReserveRegistrationNumber();
            this.RegistrationContext   = registrationContextData;
            this.IsDecorator           = isDecorator;
            this.ShouldHandleDisposal  = shouldHandleDisposal;

            this.HasName = this.RegistrationContext.Name != null;

            this.HasScopeName = this.RegistrationContext.Lifetime is NamedScopeLifetime;

            this.HasCondition = this.RegistrationContext.TargetTypeCondition != null || this.RegistrationContext.ResolutionCondition != null ||
                                this.RegistrationContext.AttributeConditions != null && this.RegistrationContext.AttributeConditions.Count > 0;

            this.RegistrationId = this.RegistrationContext.Name ??
                                  (containerConfigurator.ContainerConfiguration.SetUniqueRegistrationNames
                ? (object)this.RegistrationNumber
                : implementationType);
        }
Exemple #4
0
 internal ServiceRegistration(Type serviceType, Type implementationType, IContainerContext containerContext,
                              IObjectBuilder objectBuilder, RegistrationContextData registrationContextData,
                              bool isDecorator, bool shouldHandleDisposal)
 {
     this.objectBuilder        = objectBuilder;
     this.ImplementationType   = implementationType;
     this.ServiceType          = serviceType;
     this.MetaInformation      = GetOrCreateMetaInfo(implementationType);
     this.RegistrationNumber   = containerContext.ReserveRegistrationNumber();
     this.RegistrationContext  = registrationContextData;
     this.IsDecorator          = isDecorator;
     this.ShouldHandleDisposal = shouldHandleDisposal;
 }
Exemple #5
0
        private static MetaInformation GetOrCreateMetaInfo(Type typeTo, RegistrationContextData registrationContextData)
        {
            var found = MetaRepository.GetOrDefault(typeTo);

            if (found != null)
            {
                return(found);
            }

            var meta = new MetaInformation(typeTo, registrationContextData);

            Swap.SwapValue(ref MetaRepository, repo => repo.AddOrUpdate(typeTo, meta));
            return(meta);
        }
Exemple #6
0
        private ConstructorInformation FindSelectedConstructor(RegistrationContextData registrationContextData, MetaInformation metaInfo)
        {
            if (registrationContextData.SelectedConstructor == null)
            {
                return(null);
            }

            var length = metaInfo.Constructors.Length;

            for (var i = 0; i < length; i++)
            {
                var current = metaInfo.Constructors[i];
                if (current.Constructor == registrationContextData.SelectedConstructor)
                {
                    return(current);
                }
            }

            return(null);
        }
Exemple #7
0
 /// <inheritdoc />
 public IRegistrationContext PrepareContext(Type serviceType, Type implementationType,
                                            RegistrationContextData registrationContextData) =>
 new RegistrationContext(serviceType, implementationType, this, registrationContextData);