This is how you can use Castle Windsor’s fluent interface to auto-register all the types within one or more assemblies:
private static void RegisterTypes(WindsorContainer container)
{
var assemblies = GetAssembliesToRegister();
foreach (var assembly in assemblies)
{
container.Register(
AllTypes.Pick().FromAssemblyNamed(assembly)
.If(x => x.IsPublic)
.If(x => x.GetInterfaces().Length > 0)
.Configure(x => x.LifeStyle.Transient)
.WithService.FirstInterface()
);
}
}
private static List<string> GetAssembliesToRegister()
{
var assemblies = new List<string>();
assemblies.Add("DemoApp.DataAccess");
assemblies.Add("DemoApp.BusinessLogic");
return assemblies;
}

May 20th, 2010 at 6:56 am
Cool, will this be able to handle scenarios where implementation and interface resides in separate assemblies?
May 20th, 2010 at 7:34 am
Yes it will. The interface can reside in DemoApp.BusinessLogic while the implementation resides in DemoApp.DataAccess.