blob: 75cc206b674ca0a7e5351409b2a686c68a685b10 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
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<Interface>() {
return underlyingContainer.Kernel.Resolve<Interface>();
}
public void Register(Type typeOfInterface, Type typeOfImplementation) {
underlyingContainer
.Kernel
.AddComponent("{0}-{1}".FormatWith(typeOfInterface.FullName, typeOfImplementation.FullName),
typeOfInterface,
typeOfImplementation);
}
public void Register<Interface, Implementation>() {
Register(typeof (Interface), typeof (Implementation));
}
public void RegisterInstanceOf<Interface>(Interface instanceOfTheInterface) {
underlyingContainer.Kernel.AddComponentInstance<Interface>(instanceOfTheInterface);
}
public IEnumerable<Interface> AllImplementationsOf<Interface>() {
return underlyingContainer.Kernel.ResolveAll<Interface>();
}
}
}
|