Ejemplo n.º 1
0
        /// <summary>
        ///     Creates (but not register) new component definition
        /// </summary>
        /// <param name="name"> </param>
        /// <param name="priority"> </param>
        /// <param name="implementation"> </param>
        /// <typeparam name="TService"> </typeparam>
        /// <returns> </returns>
        public IComponentDefinition NewExtension <TService>(TService implementation, string name = "", int priority = 10000)
            where TService : class
        {
            var result = new ComponentDefinition
            {
                ServiceType        = typeof(TService),
                ImplementationType = implementation.GetType(),
                Implementation     = implementation,
                Lifestyle          = Lifestyle.Extension,
                Priority           = priority,
                Name = name
            };

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     generates ioc component definition
        /// </summary>
        /// <returns> </returns>
        public IEnumerable <IComponentDefinition> GetComponents()
        {
            foreach (var d in Descriptors)
            {
                IList <ComponentDefinition> components = new List <ComponentDefinition>();
                var stype     = d.ServiceType ?? AutoDetectedServiceType;
                var impltype  = Type;
                var lifestyle = (d.Lifestyle == Lifestyle.Default && null != AssemblyManifest)
                                    ? AssemblyManifest.Descriptor.Lifestyle
                                    : d.Lifestyle;
                var priority = (d.Priority == -1 && null != AssemblyManifest)
                                   ? AssemblyManifest.Descriptor.Priority
                                   : d.Priority;
                var names    = d.Names ?? new[] { d.Name };
                var services = d.ServiceTypes ?? new[] { stype };

                foreach (var name in names)
                {
                    foreach (var service in services)
                    {
                        var subresult = new ComponentDefinition(service, impltype, lifestyle, name, priority)
                        {
                            Role = d.Role, Help = d.Help, Tag = d.Tag
                        };
                        components.Add(subresult);
                    }
                }
                if (lifestyle == Lifestyle.Singleton && components.Count != 1)
                {
                    foreach (var c in components)
                    {
                        c.LinkedSingletons = components.Where(_ => !Equals(_, c)).ToArray();
                    }
                }

                foreach (var componentDefinition in components)
                {
                    yield return(componentDefinition);
                }
            }
        }