Created
July 12, 2010 16:32
-
-
Save KevM/472687 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class AutoMessageConsumerSubscriptionService : IRequiredService | |
| { | |
| private readonly IContainer _container; | |
| private readonly IServiceBus _serviceBus; | |
| private readonly ILogger _logger; | |
| public AutoMessageConsumerSubscriptionService(IContainer container, IServiceBus serviceBus, ILogger logger) | |
| { | |
| _container = container; | |
| _serviceBus = serviceBus; | |
| _logger = logger; | |
| } | |
| public void Start() | |
| { | |
| AutoSubscribeMessageConsumers(_container, _serviceBus, _logger); | |
| } | |
| public static void AutoSubscribeMessageConsumers(IContainer container, IServiceBus serviceBus, ILogger logger) | |
| { | |
| var consumerInstances = container.Model.InstancesOf(typeof(IMessageConsumer<>)); | |
| logger.LogDebug("Found {0} message consumers.", consumerInstances.Count()); | |
| foreach (var consumerInstance in consumerInstances) | |
| { | |
| logger.LogDebug("Subscribing message consumer {0}.", consumerInstance.Name); | |
| serviceBus.Subscribe(consumerInstance.ConcreteType); | |
| } | |
| } | |
| public void Stop() | |
| { | |
| _serviceBus.Dispose(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment