Permalink
Browse files

getting warmer on the circular dependency thing

  • Loading branch information...
1 parent 88dbfd2 commit 404b95508be5876b8f0c594dc78979781044a679 @drusellers drusellers committed Jan 10, 2008
@@ -42,7 +42,7 @@ public void Registering_with_the_bus()
{
LocalSubscriptionCache cache = new LocalSubscriptionCache();
- cache.RegisterWithBus(bus);
+ cache.Initialize(bus);
}
}
@@ -80,7 +80,7 @@ public void Add_Subscription_with_a_bus()
using (mocks.Playback())
{
- cache.RegisterWithBus(bus);
+ cache.Initialize(bus);
cache.Add(typeof(PingMessage), mockEndpoint);
}
@@ -8,7 +8,7 @@ namespace MassTransit.ServiceBus.Subscriptions
public class LocalSubscriptionCache :
ISubscriptionStorage
{
- private IServiceBus _bus;
+ private IServiceBus _bus = new NullBus();
private IEndpoint _wellKnownSubscriptionManagerEndpoint;
private readonly Dictionary<Type, List<SubscriptionCacheEntry>> _messageTypeSubscriptions =
new Dictionary<Type, List<SubscriptionCacheEntry>>();
@@ -30,8 +30,11 @@ public LocalSubscriptionCache(IEndpoint wellKnownSubscriptionManagerEndpoint)
_wellKnownSubscriptionManagerEndpoint = wellKnownSubscriptionManagerEndpoint;
}
- public void Initialize()
+ public void Initialize(IServiceBus bus)
{
+ //TODO: Think about putting this behind a setter?
+ _bus = bus;
+ _bus.Subscribe<CacheUpdateResponse>(ReactToCacheUpdateResponse);
InternalSend(new RequestCacheUpdate());
}
@@ -143,16 +146,51 @@ private void InternalAdd(Type messageType, IEndpoint endpoint)
private void InternalSend(params IMessage[] message)
{
- if (_bus != null)
- {
- _bus.Send(_wellKnownSubscriptionManagerEndpoint, message);
- }
+ _bus.Send(_wellKnownSubscriptionManagerEndpoint, message);
}
- public void RegisterWithBus(IServiceBus bus)
+ private class NullBus : IServiceBus
{
- _bus = bus;
- _bus.Subscribe<CacheUpdateResponse>(ReactToCacheUpdateResponse);
+ public IEndpoint Endpoint
+ {
+ get { return null; }
+ }
+
+ public IEndpoint PoisonEndpoint
+ {
+ get { return null; }
+ }
+
+ public void Subscribe<T>(MessageReceivedCallback<T> callback) where T : IMessage
+ {
+ //ignore
+ }
+
+ public void Subscribe<T>(MessageReceivedCallback<T> callback, Predicate<T> condition) where T : IMessage
+ {
+ //ignore
+ }
+
+ public void Publish<T>(params T[] messages) where T : IMessage
+ {
+ //ignore
+ }
+
+ public IServiceBusAsyncResult Request<T>(IEndpoint destinationEndpoint, params T[] messages)
+ where T : IMessage
+ {
+ return null;
+ }
+
+ public void Send<T>(IEndpoint destinationEndpoint, params T[] messages) where T : IMessage
+ {
+ //ignore
+ }
+
+ public void Dispose()
+ {
+ //ignore
+ }
}
}
}

0 comments on commit 404b955

Please sign in to comment.