Exemplo n.º 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);
        }
Exemplo n.º 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();
        }
Exemplo n.º 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);
        }
Exemplo n.º 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;
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 7
0
 /// <inheritdoc />
 public IRegistrationContext PrepareContext(Type serviceType, Type implementationType,
                                            RegistrationContextData registrationContextData) =>
 new RegistrationContext(serviceType, implementationType, this, registrationContextData);