FromAssembly
using Castle.Core.Internal;
using Castle.MicroKernel.Registration;
using System;
using System.Collections.Generic;
using System.Reflection;
namespace Castle.Windsor.Installer
{
public class FromAssembly
{
public static IWindsorInstaller Containing(Type type)
{
if ((object)type == null)
throw new ArgumentNullException("type");
return Instance(type.GetTypeInfo().get_Assembly());
}
public static IWindsorInstaller Containing(Type type, InstallerFactory installerFactory)
{
if ((object)type == null)
throw new ArgumentNullException("type");
return Instance(type.GetTypeInfo().get_Assembly(), installerFactory);
}
public static IWindsorInstaller Containing<T>()
{
return Containing(typeof(T));
}
public static IWindsorInstaller Containing<T>(InstallerFactory installerFactory)
{
return Containing(typeof(T), installerFactory);
}
public static IWindsorInstaller InDirectory(AssemblyFilter filter)
{
return InDirectory(filter, new InstallerFactory());
}
public static IWindsorInstaller InDirectory(AssemblyFilter filter, InstallerFactory installerFactory)
{
HashSet<Assembly> hashSet = new HashSet<Assembly>(ReflectionUtil.GetAssemblies(filter));
CompositeInstaller compositeInstaller = new CompositeInstaller();
foreach (Assembly item in hashSet) {
compositeInstaller.Add(Instance(item, installerFactory));
}
return compositeInstaller;
}
public static IWindsorInstaller InThisApplication(Assembly rootAssembly)
{
return ApplicationAssemblies(rootAssembly, new InstallerFactory());
}
public static IWindsorInstaller InThisApplication(Assembly rootAssembly, InstallerFactory installerFactory)
{
return ApplicationAssemblies(rootAssembly, installerFactory);
}
public static IWindsorInstaller Instance(Assembly assembly)
{
return Instance(assembly, new InstallerFactory());
}
public static IWindsorInstaller Instance(Assembly assembly, InstallerFactory installerFactory)
{
return new AssemblyInstaller(assembly, installerFactory);
}
public static IWindsorInstaller Named(string assemblyName)
{
return Instance(ReflectionUtil.GetAssemblyNamed(assemblyName));
}
public static IWindsorInstaller Named(string assemblyName, InstallerFactory installerFactory)
{
return Instance(ReflectionUtil.GetAssemblyNamed(assemblyName), installerFactory);
}
private static IWindsorInstaller ApplicationAssemblies(Assembly rootAssembly, InstallerFactory installerFactory)
{
HashSet<Assembly> hashSet = new HashSet<Assembly>(ReflectionUtil.GetApplicationAssemblies(rootAssembly));
CompositeInstaller compositeInstaller = new CompositeInstaller();
foreach (Assembly item in hashSet) {
compositeInstaller.Add(Instance(item, installerFactory));
}
return compositeInstaller;
}
}
}