Provides a SimpleInjector-based container adapter for Rebus.
To configure Rebus to work with your SimpleInjector container, simply call
container.RegisterRebus(
configurer => configurer
.(...)
);
where the (...)
is the part usually omitted from the Rebus configuration examples.
A slightly more realistic example (using Serilog, RabbitMQ and SQL Server) could look like this:
container.RegisterRebus(
configurer => configurer
.Logging(l => l.Serilog())
.Transport(t => t.UseRabbitMq("amqp://rebususer:blablasecret@BIGRABBIT01.local", "simpleinjectortest"))
.Sagas(s => s.StoreInSqlServer("server=SQLMOTEL01.local; database=RebusStuff; trusted_connection=true"))
);
The examples shown so far will make the necessary container registrations, but the bus will not be started until either
- The container resolves the
IBus
instance, or - You call the
container.StartBus()
extension method
so you should probably always remember to call container.StartBus()
when your application starts (after it has
finished making ALL of its container registrations).
Beacuse SimpleInjector is very opinionated about its registration API and Rebus is pretty loose about it :)
Since Rebus' container adapters resolve ALL handlers that can handle an incoming message, handlers must be registered with the registration API for collections, e.g. like
container.RegisterCollection<IHandleMessages<SomeMessage>>(new []{ typeof(SomeMessageHandler) });