forked from hibernating-rhinos/rhino-esb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOnewayRhinoServiceBusFacility.cs
77 lines (71 loc) · 2.88 KB
/
OnewayRhinoServiceBusFacility.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Messaging;
using System.Transactions;
using Castle.Core;
using Castle.MicroKernel.Facilities;
using Castle.MicroKernel.Registration;
using Rhino.Queues;
using Rhino.ServiceBus.Internal;
using Rhino.ServiceBus.Msmq;
using Rhino.ServiceBus.RhinoQueues;
using Rhino.ServiceBus.Serializers;
using System.Linq;
namespace Rhino.ServiceBus.Impl
{
public class OnewayRhinoServiceBusFacility : AbstractFacility
{
private readonly List<MessageOwner> messageOwners = new List<MessageOwner>();
private Type serializerImpl = typeof(XmlMessageSerializer);
public void UseMessageSerializer<TMessageSerializer>()
{
serializerImpl = typeof(TMessageSerializer);
}
protected override void Init()
{
var messageOwnersReader = new MessageOwnersConfigReader(FacilityConfig, messageOwners);
messageOwnersReader.ReadMessageOwners();
if (IsRhinoQueues(messageOwnersReader.EndpointScheme))
{
Kernel.Register(
Component.For<IMessageBuilder<MessagePayload>>()
.ImplementedBy<RhinoQueuesMessageBuilder>()
.LifeStyle.Is(LifestyleType.Singleton),
Component.For<IOnewayBus>()
.LifeStyle.Is(LifestyleType.Singleton)
.ImplementedBy<RhinoQueuesOneWayBus>()
.DependsOn(new
{
messageOwners = messageOwners.ToArray(),
})
);
}
else
{
Kernel.Register(
Component.For<IMessageBuilder<Message>>()
.LifeStyle.Is(LifestyleType.Singleton)
.ImplementedBy<MsmqMessageBuilder>(),
Component.For<IOnewayBus>()
.LifeStyle.Is(LifestyleType.Singleton)
.ImplementedBy<MsmqOnewayBus>()
.DependsOn(new {messageOwners = messageOwners.ToArray()}));
}
Kernel.Register(
Component.For<IReflection>()
.LifeStyle.Is(LifestyleType.Singleton)
.ImplementedBy<DefaultReflection>(),
Component.For<IMessageSerializer>()
.LifeStyle.Is(LifestyleType.Singleton)
.ImplementedBy(serializerImpl),
Component.For<IEndpointRouter>()
.ImplementedBy<EndpointRouter>()
);
}
private static bool IsRhinoQueues(string endpointScheme)
{
return endpointScheme.Equals("rhino.queues", StringComparison.InvariantCultureIgnoreCase);
}
}
}