views:

157

answers:

2

Hey guys, here's 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?

cheers

andy

+3  A: 

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

Andreas
how do you mean? I would just have to get my current instance of the container, and go .Resolve<IBus>()? without having to configure IBus in my windsor.config?
andy
Also, Andreas, how would that work when NServiceBus is running under a separate process... i.e. a service? can that work?
andy
Yes the bus would be available using .ResolveNot following you on the other q: You always communicate using an instance of the bus running in the same process as your own code. Eg. If you have a webb app sending commands to a backend service hosted in the NSB generic host you would configure NSB in you web app as well and do a bus.Send(new WhateverMessage())Inshort: NSB always run in the same process as you code that interacts with the busDoes this help?
Andreas
yep, perfect, thanks andreas. I think I got a bit confused, but I just wanted some confirmation from someone else. good stuff!
andy
A: 

Hi Andy,

Could you explain how you got this to work? I am having trouble with container.Resolve().

How do I get NServiceBus to register its dependencies into my container? I Want to be able to resolve IBus as a dependency in my own class.

I have the following already:

Configure.With()
            .CastleWindsorBuilder(Container.Instance)
            .XmlSerializer()
            .CreateBus();
Tim
hey tim, this needs to be a question on it's own, then you've got more space to discuss the issues. open a new question and update this answer with the link to the question. cheers!
andy