Created
June 16, 2015 17:37
-
-
Save sjdweb/4ae29fc71383a4954f2f to your computer and use it in GitHub Desktop.
MassTransit StructureMap Extensions
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
namespace MyApp.MassTransitExtensions | |
{ | |
using MassTransit; | |
using StructureMap; | |
using StructureMap.Graph; | |
public static class MassTransitStructureMapExtensions | |
{ | |
public static void ScanConsumers(this IContainer container) | |
{ | |
container.Configure( | |
x => | |
{ | |
x.Scan( | |
s => | |
{ | |
s.TheCallingAssembly(); | |
s.AddAllTypesOf<IConsumer>(); | |
}); | |
}); | |
} | |
public static void InjectBus(this IContainer container) | |
{ | |
var bus = ServiceBusFactory.New( | |
sbc => | |
{ | |
sbc.UseRabbitMq(); | |
sbc.ReceiveFrom("rabbitmq://localhost/myqueue"); | |
sbc.UseJsonSerializer(); | |
sbc.Subscribe(s => s.LoadFrom(container)); | |
}); | |
container.Configure( | |
c => | |
{ | |
c.For<IServiceBus>().Singleton().Use(x => bus); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment