我正在使用MT 3.1.0和Castle windsor 3.3.0。
使用windsor安装程序我已初始化容器。
public void Install(IWindsorContainer container,IConfigurationStore store)
{
var busControl = Bus.Factory.CreateUsingRabbitMq(cfg =>
{
var host = cfg.Host(new Uri("rabbitmq://localhost"), h =>
{
h.Username("guest");
h.Password("guest");
});
cfg.ReceiveEndpoint(host, "testq", e =>
{
e.EnableMessageScope();
e.LoadFrom(container);
});
});
container.Register(Component.For<IBus>().Instance(busControl));
busControl.Start();
}
在Application_Start()内部配置容器
_container = WindsorConfiguration.Configure(GlobalConfiguration.Configuration);
来自API控制器
[RoutePrefix("api/Test")]
public class TestController : ApiController
{
private readonly IBus _bus;
}
public TestController(IBus bus)
{
_bus = bus;
}
[HttpPost]
[Route("PublishMessage")]
public async Task<IHttpActionResult> PublishMessage()
{
await _bus.Publish(new TestMessage
{
TestId = 1
});
return Ok("Success!");
}
它在_bus.Publish
处抛出空引用异常