Last active
October 8, 2015 14:46
-
-
Save Uli-Armbruster/45e51f8a9712e51acb3e to your computer and use it in GitHub Desktop.
Open Closed Principle with Castle.Windsor Collection Resolver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
container.Register(Components().ToArray()); | |
} | |
private static IEnumerable<IRegistration> Components() | |
{ | |
//have a look at https://github.com/castleproject/Windsor/blob/master/docs/registering-components-by-conventions.md | |
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() | |
.LifestyleTransient(); | |
yield return Component | |
.For<IBar>() | |
.ImplementedBy<Bar>() | |
.LifestyleTransient(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment