Classes
Entry point to fluent way to register, by convention, multiple concrete (non-abstract) classes (that include also delegate types). Use static methods on the class to fluently build
registration.
using Castle.Core.Internal;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace Castle.MicroKernel.Registration
{
public static class Classes
{
public static FromTypesDescriptor From(IEnumerable<Type> types)
{
return new FromTypesDescriptor(types, Filter);
}
public static FromTypesDescriptor From(params Type[] types)
{
return new FromTypesDescriptor(types, Filter);
}
public static FromAssemblyDescriptor FromAssembly(Assembly assembly)
{
if (assembly == (Assembly)null)
throw new ArgumentNullException("assembly");
return new FromAssemblyDescriptor(assembly, Filter);
}
public static FromAssemblyDescriptor FromAssemblyContaining(Type type)
{
if (type == (Type)null)
throw new ArgumentNullException("type");
return new FromAssemblyDescriptor(type.GetTypeInfo().Assembly, Filter);
}
public static FromAssemblyDescriptor FromAssemblyContaining<T>()
{
return FromAssemblyContaining(typeof(T));
}
public static FromAssemblyDescriptor FromAssemblyInDirectory(AssemblyFilter filter)
{
if (filter == null)
throw new ArgumentNullException("filter");
return new FromAssemblyDescriptor(ReflectionUtil.GetAssemblies(filter), Filter);
}
[MethodImpl(MethodImplOptions.NoInlining)]
public static FromAssemblyDescriptor FromAssemblyInThisApplication()
{
return FromAssemblyInThisApplication(Assembly.GetCallingAssembly());
}
public static FromAssemblyDescriptor FromAssemblyInThisApplication(Assembly rootAssembly)
{
return new FromAssemblyDescriptor(new HashSet<Assembly>(ReflectionUtil.GetApplicationAssemblies(rootAssembly)), Filter);
}
public static FromAssemblyDescriptor FromAssemblyNamed(string assemblyName)
{
return FromAssembly(ReflectionUtil.GetAssemblyNamed(assemblyName));
}
[MethodImpl(MethodImplOptions.NoInlining)]
public static FromAssemblyDescriptor FromThisAssembly()
{
return FromAssembly(Assembly.GetCallingAssembly());
}
[EditorBrowsable(EditorBrowsableState.Never)]
internal static bool Filter(Type type)
{
if (type.GetTypeInfo().IsClass)
return !type.GetTypeInfo().IsAbstract;
return false;
}
}
}