forked from hibernating-rhinos/rhino-esb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCastleBootStrapper.cs
102 lines (88 loc) · 3.08 KB
/
CastleBootStrapper.cs
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System.Reflection;
using Castle.Core;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using Rhino.ServiceBus.Actions;
using Rhino.ServiceBus.Hosting;
using Rhino.ServiceBus.Impl;
using Rhino.ServiceBus.Internal;
namespace Rhino.ServiceBus.Castle
{
public abstract class CastleBootStrapper : AbstractBootStrapper
{
private IWindsorContainer container;
protected CastleBootStrapper()
{
}
protected CastleBootStrapper(IWindsorContainer container)
{
this.container = container;
}
protected IWindsorContainer Container
{
get { return container; }
}
protected override void ConfigureBusFacility(AbstractRhinoServiceBusConfiguration configuration)
{
configuration.UseCastleWindsor(container);
}
public override void ExecuteDeploymentActions(string user)
{
foreach (var action in container.ResolveAll<IDeploymentAction>())
action.Execute(user);
}
public override void ExecuteEnvironmentValidationActions()
{
foreach (var action in container.ResolveAll<IEnvironmentValidationAction>())
action.Execute();
}
public override T GetInstance<T>()
{
return container.Resolve<T>();
}
public override void Dispose()
{
container.Dispose();
}
public override void CreateContainer()
{
if (container == null)
container = new WindsorContainer();
ConfigureContainer();
}
protected virtual void ConfigureContainer()
{
foreach (var assembly in Assemblies)
{
container.Register(
AllTypes.FromAssembly(assembly)
.BasedOn<IDeploymentAction>(),
AllTypes.FromAssembly(assembly)
.BasedOn<IEnvironmentValidationAction>()
);
RegisterConsumersFrom(assembly);
}
}
protected virtual void RegisterConsumersFrom(Assembly assembly)
{
container.Register(
AllTypes
.FromAssembly(assembly)
.Where(type =>
typeof(IMessageConsumer).IsAssignableFrom(type) &&
!typeof(IOccasionalMessageConsumer).IsAssignableFrom(type) &&
IsTypeAcceptableForThisBootStrapper(type)
)
.Configure(registration =>
{
registration.LifeStyle.Is(LifestyleType.Transient);
ConfigureConsumer(registration);
})
);
}
protected virtual void ConfigureConsumer(ComponentRegistration registration)
{
registration.Named(registration.Implementation.FullName);
}
}
}