我正在尝试将DI与我的消费者类一起使用而没有成功.
我的消费者阶层:
public class TakeMeasureConsumer : IConsumer<TakeMeasure>
{
private IUnitOfWorkAsync _uow;
private IInstrumentOutputDomainService _instrumentOutputDomainService;
public TakeMeasureConsumer(IUnitOfWorkAsync uow,
IInstrumentOutputDomainService instrumentOutputDomainService)
{
_uow = uow;
_instrumentOutputDomainService = instrumentOutputDomainService;
}
public async Task Consume(ConsumeContext<TakeMeasure> context)
{
var instrumentOutput = Mapper.Map<InstrumentOutput>(context.Message);
_instrumentOutputDomainService.Insert(instrumentOutput);
await _uow.SaveChangesAsync();
}
}
Run Code Online (Sandbox Code Playgroud)
当我想注册总线工厂时,消费者必须有一个无参数构造函数.
protected override void Load(ContainerBuilder builder)
{
builder.Register(context =>
Bus.Factory.CreateUsingRabbitMq(cfg =>
{
var host = cfg.Host(new Uri("rabbitmq://localhost/"), h =>
{
h.Username("guest");
h.Password("guest");
});
cfg.ReceiveEndpoint(host, "intrument_take_measure", e =>
{
// Must be a non abastract type with a parameterless …Run Code Online (Sandbox Code Playgroud)