Skip to content

macchmie3/Rebus.SimpleInjector

 
 

Repository files navigation

Rebus.SimpleInjector

install from nuget

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

  1. The container resolves the IBus instance, or
  2. 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).

So why is it different from all the other container adapters?

Beacuse SimpleInjector is very opinionated about its registration API and Rebus is pretty loose about it :)

How to register handlers?

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) });

About

🚌 SimpleInjector container adapter for Rebus

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 91.8%
  • Batchfile 8.2%