I´m trying to send a message to the queue from my WebApi application. The first time the server starts everything goes fine and I can send a message to the queue from my controller, but the next time the action is called it throws the folloowing exception:
Cannot access a disposed object.
Object name: 'UnicastBus'.
This is how I´m binding the IBus interface
public static class NinjectWebCommon
{
...
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<IBus>().ToConstant(CreateBus()).InSingletonScope();
}
private static IBus CreateBus()
{
Configure.Serialization.Xml();
return Configure.With()
.DefaultBuilder()
.UseTransport<Msmq>()
.UnicastBus()
.SendOnly();
}
}
And in my controller
public class CreatedOrderMessageController : ApiController
{
private readonly IBus bus;
public CreatedOrderMessageController(IBus bus)
{
this.bus = bus;
}
public string Get(int id)
{
bus.Send(new OrderCreatedMessage(id));
return "true";
}
}
Any thoughts on this error?
Thanks