Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Open Closed Principle with Castle.Windsor Collection Resolver
public class Installer : IWindsorInstaller
/// <summary>
/// Performs the installation in the <see cref="T:Castle.Windsor.IWindsorContainer" />.
/// </summary>
/// <param name="container">The container.</param>
/// <param name="store">The configuration store.</param>
public void Install(IWindsorContainer container, IConfigurationStore store)
container.Kernel.Resolver.AddSubResolver(new Castle.MicroKernel.Resolvers.SpecializedResolvers.CollectionResolver(container.Kernel));
private static IEnumerable<IRegistration> Components()
//have a look at
yield return Classes //non abstract classes; you could also use Types.* for more choices
.FromThisAssembly() //should be clear
.IncludeNonPublicTypes() //since my implementations are internal, only the interface is public
.BasedOn<IFoo>() //every class that implements this interface
.WithService.Base() //also possible: .WithServiceFromInterface()
yield return Component
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment