master
 1using System;
 2using System.Collections.Generic;
 3using Castle.Windsor;
 4using Notepad.Infrastructure.Extensions;
 5
 6namespace Notepad.Infrastructure.Container.Windsor {
 7    public class WindsorDependencyRegistry : IDependencyRegistry {
 8        private IWindsorContainer underlyingContainer;
 9
10        public WindsorDependencyRegistry() : this(new WindsorContainerFactory()) {}
11
12        public WindsorDependencyRegistry(IWindsorContainerFactory factory) {
13            underlyingContainer = factory.Create();
14        }
15
16        public Interface FindAnImplementationOf<Interface>() {
17            return underlyingContainer.Kernel.Resolve<Interface>();
18        }
19
20        public void Register(Type typeOfInterface, Type typeOfImplementation) {
21            underlyingContainer
22                .Kernel
23                .AddComponent("{0}-{1}".FormatWith(typeOfInterface.FullName, typeOfImplementation.FullName),
24                              typeOfInterface,
25                              typeOfImplementation);
26        }
27
28        public void Register<Interface, Implementation>() {
29            Register(typeof (Interface), typeof (Implementation));
30        }
31
32        public void RegisterInstanceOf<Interface>(Interface instanceOfTheInterface) {
33            underlyingContainer.Kernel.AddComponentInstance<Interface>(instanceOfTheInterface);
34        }
35
36        public IEnumerable<Interface> AllImplementationsOf<Interface>() {
37            return underlyingContainer.Kernel.ResolveAll<Interface>();
38        }
39    }
40}