I'm trying to use DI with my consumer class without success.
My consumer class:
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();
}
}
When I want to register the bus factory the consumer must have a parameterless constructor.
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 constructor....
e.Consumer<TakeMeasureConsumer>();
});
}))
.SingleInstance()
.As<IBusControl>()
.As<IBus>();
}
Any help would be appreciated, I really don't know how to register my consumer...
Thanks