When creating a nServiceBus host with an EndpointName in the configuration be warned for this structuremap interference. See the repro code below of a bug we recently fixed. The messages and handlers are left out of the sample for simplicity.
Bug
The IoC container is initialized by scanning all types in the current assembly.
public class IoC { public static void Init() { ObjectFactory.Initialize(factory => { factory.Scan(scan => { scan.TheCallingAssembly(); }); }); } }
Initialization of the nServicebus with IoC and a name for the endpoint (queue)
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization { public void Init() { IoC.Init(); // expect name of queue to be CityBus Configure.With() .StructureMapBuilder(ObjectFactory.Container) .DefineEndpointName("CityBus"); } }
But when the project starts the output window tells me the queue is created with the default naming convention using the assembly namespace. The retries, timeouts and timeoutsdispatcher queue are correct. The main queue is (wrongly) named StructureMap.QueueName after the namespace.
Solution
The structuremap scan will create the endpoint with default convention as it executed before the DefineEndpointName. By moving the code before the scan the correct queue is created.
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization { public void Init() { // expect name of queue to be CityBus Configure.With().DefineEndpointName("CityBus"); IoC.Init(); Configure.With() .StructureMapBuilder(ObjectFactory.Container); } }
Now manually remove the StructureMap.QueueName as it is no longer needed.
Full repro project download here.