using System; using System.Collections.Generic; using Castle.Windsor; using Notepad.Infrastructure.Extensions; namespace Notepad.Infrastructure.Container.Windsor { public class WindsorDependencyRegistry : IDependencyRegistry { private IWindsorContainer underlyingContainer; public WindsorDependencyRegistry() : this(new WindsorContainerFactory()) {} public WindsorDependencyRegistry(IWindsorContainerFactory factory) { underlyingContainer = factory.Create(); } public Interface FindAnImplementationOf() { return underlyingContainer.Kernel.Resolve(); } public void Register(Type typeOfInterface, Type typeOfImplementation) { underlyingContainer .Kernel .AddComponent("{0}-{1}".FormatWith(typeOfInterface.FullName, typeOfImplementation.FullName), typeOfInterface, typeOfImplementation); } public void Register() { Register(typeof (Interface), typeof (Implementation)); } public void RegisterInstanceOf(Interface instanceOfTheInterface) { underlyingContainer.Kernel.AddComponentInstance(instanceOfTheInterface); } public IEnumerable AllImplementationsOf() { return underlyingContainer.Kernel.ResolveAll(); } } }