Skip to content

Instantly share code, notes, and snippets.

@jokokko
Created July 29, 2014 15:09
Show Gist options
  • Save jokokko/8538f5c203a6464e8801 to your computer and use it in GitHub Desktop.
Save jokokko/8538f5c203a6464e8801 to your computer and use it in GitHub Desktop.
NSB manual consumer wireup
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