Created
July 29, 2014 15:09
-
-
Save jokokko/8538f5c203a6464e8801 to your computer and use it in GitHub Desktop.
NSB manual consumer wireup
This file contains 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 static class SubscriptionExtensions | |
{ | |
internal sealed class UsingCustomMessageHandlerRegistry | |
{ | |
} | |
public static void Consumer<T>(this UnicastBus busInstance, IHandleMessages<T> handler) | |
{ | |
var currentConfiguration = Configure.Instance; | |
MessageHandlerRegistry messageHandlerRegistry; | |
if (currentConfiguration.Configurer.HasComponent<UsingCustomMessageHandlerRegistry>()) | |
{ | |
messageHandlerRegistry = (MessageHandlerRegistry)currentConfiguration.Builder.Build<IMessageHandlerRegistry>(); | |
} | |
else | |
{ | |
messageHandlerRegistry = new MessageHandlerRegistry(); | |
currentConfiguration.Configurer.ConfigureComponent<UsingCustomMessageHandlerRegistry>(DependencyLifecycle.SingleInstance); | |
currentConfiguration.Configurer.RegisterSingleton<IMessageHandlerRegistry>(messageHandlerRegistry); | |
} | |
busInstance.Subscribe(typeof(T)); | |
messageHandlerRegistry.RegisterHandler(handler.GetType()); | |
currentConfiguration.Configurer.ConfigureComponent(handler.GetType(), DependencyLifecycle.SingleInstance); | |
currentConfiguration.Configurer.RegisterSingleton(handler.GetType(), handler); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment