Component
Factory for creating  ComponentRegistration objects. Use static methods on the class to fluently build registration.
            
                using Castle.Core;
using System;
using System.Collections.Generic;
using System.Reflection;
namespace Castle.MicroKernel.Registration
{
    public static class Component
    {
        public static ComponentRegistration For(Type serviceType)
        {
            if ((object)serviceType == null)
                throw new ArgumentNullException("serviceType", "The argument was null. Check that the assembly is referenced and the type available to your application.");
            return new ComponentRegistration(serviceType);
        }
        public static ComponentRegistration For(params Type[] serviceTypes)
        {
            if (serviceTypes.Length == 0)
                throw new ArgumentException("At least one service type must be supplied");
            return new ComponentRegistration(serviceTypes);
        }
        public static ComponentRegistration For(IEnumerable<Type> serviceTypes)
        {
            ComponentRegistration componentRegistration = null;
            foreach (Type serviceType in serviceTypes) {
                if (componentRegistration == null)
                    componentRegistration = For(serviceType);
                else
                    componentRegistration.Forward(serviceType);
            }
            if (componentRegistration == null)
                throw new ArgumentException("At least one service type must be supplied");
            return componentRegistration;
        }
        public static ComponentRegistration<TService> For<TService>() where TService : class
        {
            return new ComponentRegistration<TService>();
        }
        public static ComponentRegistration<TService1> For<TService1, TService2>() where TService1 : class
        {
            return new ComponentRegistration<TService1>().Forward<TService2>();
        }
        public static ComponentRegistration<TService1> For<TService1, TService2, TService3>() where TService1 : class
        {
            return new ComponentRegistration<TService1>().Forward<TService2, TService3>();
        }
        public static ComponentRegistration<TService1> For<TService1, TService2, TService3, TService4>() where TService1 : class
        {
            return new ComponentRegistration<TService1>().Forward<TService2, TService3, TService4>();
        }
        public static ComponentRegistration<TService1> For<TService1, TService2, TService3, TService4, TService5>() where TService1 : class
        {
            return new ComponentRegistration<TService1>().Forward<TService2, TService3, TService4, TService5>();
        }
        public static bool HasAttribute<TAttribute>(Type type) where TAttribute : Attribute
        {
            return CustomAttributeExtensions.IsDefined(type.GetTypeInfo(), typeof(TAttribute));
        }
        public static Predicate<Type> HasAttribute<TAttribute>(Predicate<TAttribute> filter) where TAttribute : Attribute
        {
            return delegate(Type type) {
                if (Component.HasAttribute<TAttribute>(type))
                    return filter((TAttribute)type.GetTypeInfo().GetCustomAttribute(typeof(TAttribute)));
                return false;
            };
        }
        public static bool IsCastleComponent(Type type)
        {
            return HasAttribute<CastleComponentAttribute>(type);
        }
        public static Predicate<Type> IsInNamespace(string namespace)
        {
            return IsInNamespace(namespace, false);
        }
        public static Predicate<Type> IsInNamespace(string namespace, bool includeSubnamespaces)
        {
            if (includeSubnamespaces)
                return delegate(Type type) {
                    if (!(type.Namespace == namespace)) {
                        if (type.Namespace != null)
                            return type.Namespace.StartsWith(namespace + ".");
                        return false;
                    }
                    return true;
                };
            return (Type type) => type.Namespace == namespace;
        }
        public static Predicate<Type> IsInSameNamespaceAs(Type type)
        {
            return IsInNamespace(type.Namespace);
        }
        public static Predicate<Type> IsInSameNamespaceAs(Type type, bool includeSubnamespaces)
        {
            return IsInNamespace(type.Namespace, includeSubnamespaces);
        }
        public static Predicate<Type> IsInSameNamespaceAs<T>()
        {
            return IsInSameNamespaceAs(typeof(T));
        }
        public static Predicate<Type> IsInSameNamespaceAs<T>(bool includeSubnamespaces)
        {
            return IsInSameNamespaceAs(typeof(T), includeSubnamespaces);
        }
    }
}