Search code examples
design-patternsioc-containernservicebus

IoC, Containers, and NServiceBus confusion


Here is my setup

  • Castle Windsor is my container
  • NServiceBus is itself using it's own container internally, Spring by default
  • I'm implementing the PubSub config.

Ok, if I have my Bus.Publish happening within my IWantToRunAtStartup class, then everything is fine. As a test for example on Run() we can start a timer and it'll go into a Service style loop.

However, what if I want to abstract NServiceBus from my app, and have my app go:

new CustomPulisherClass().Notify(ISomeMessage msg);

In this situation, how do I implement CustomPublisherClass.

My confusion is coming from the fact that NServiceBus is already running as a Service, it's already been "Started". How to I get at the correct instance of the Bus object?


Solution

  • You should configure NServiceBus to use Windsor as the internal container:

    http://sourceforge.net/apps/mediawiki/nservicebus/index.php?title=Additional_containers

    If you do that the correct IBus will be available in your instance of Windsor